# Class UnsafeByteOperations (3.27.1)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [3.27.1 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.UnsafeByteOperations)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.UnsafeByteOperations)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.UnsafeByteOperations)

    public static class UnsafeByteOperations

Provides a number of unsafe byte operations to be used by advanced applications with high performance
requirements. These methods are referred to as "unsafe" due to the fact that they potentially expose
the backing buffer of a [ByteString](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString) to the application.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> UnsafeByteOperations

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Protobuf](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf)

## Assembly

Google.Protobuf.dll

## Remarks

<br />


The methods in this class should only be called if it is guaranteed that the buffer backing the
[ByteString](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString) will never change! Mutation of a [ByteString](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString) can lead to unexpected
and undesirable consequences in your application, and will likely be difficult to debug. Proceed with caution!


This can have a number of significant side affects that have spooky-action-at-a-distance-like behavior. In
particular, if the bytes value changes out from under a Protocol Buffer:

- serialization may throw
- serialization may succeed but the wrong bytes may be written out
- objects that are normally immutable (such as ByteString) are no longer immutable
- hashCode may be incorrect

<br />

## Methods

### UnsafeWrap(ReadOnlyMemory\<byte\>)

    public static ByteString UnsafeWrap(ReadOnlyMemory<byte> bytes)

Constructs a new [ByteString](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString) from the given bytes. The bytes are not copied,
and must not be modified while the [ByteString](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString) is in use.
This API is experimental and subject to change.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://learn.microsoft.com/dotnet/api/system.readonlymemory-1https://learn.microsoft.com/dotnet/api/system.byte` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString` |   |