Edit

Share via


ReadOnlyMemoryExtensions.AsStream(ReadOnlyMemory<Byte>) Method

Definition

Returns a Stream wrapping the contents of the given ReadOnlyMemory<T> of Byte instance.

public static System.IO.Stream AsStream (this ReadOnlyMemory<byte> memory);
static member AsStream : ReadOnlyMemory<byte> -> System.IO.Stream
<Extension()>
Public Function AsStream (memory As ReadOnlyMemory(Of Byte)) As Stream

Parameters

memory
ReadOnlyMemory<Byte>

The input ReadOnlyMemory<T> of Byte instance.

Returns

A Stream wrapping the data within memory.

Exceptions

Thrown when memory has an invalid data store.

Remarks

Since this method only receives a Memory<T> instance, which does not track the lifetime of its underlying buffer, it is responsibility of the caller to manage that. In particular, the caller must ensure that the target buffer is not disposed as long as the returned Stream is in use, to avoid unexpected issues.

Applies to