Edit

Share via


MemoryMarshal.AsMemory<T>(ReadOnlyMemory<T>) Method

Definition

Creates a Memory<T> instance from a ReadOnlyMemory<T>.

public static Memory<T> AsMemory<T> (ReadOnlyMemory<T> memory);

Type Parameters

T

The type of items in the read-only memory buffer.

Parameters

memory
ReadOnlyMemory<T>

The read-only memory buffer.

Returns

A memory block that represents the same memory as the ReadOnlyMemory<T>.

Remarks

Caution

This method must be used with extreme caution. ReadOnlyMemory<T> is used to represent immutable data and other memory that is not meant to be written to. Memory<T> instances created by this method should not be written to. The purpose of this method is to allow variables typed as Memory<T> but only used for reading to store a ReadOnlyMemory<T>.

Applies to

Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.0 (package-provided), 2.1