MemoryStream.TryGetBuffer(ArraySegment<Byte>) Method

Definition

Returns the array of unsigned bytes from which this stream was created. The return value indicates whether the conversion succeeded.

C#
public virtual bool TryGetBuffer(out ArraySegment<byte> buffer);

Parameters

buffer
ArraySegment<Byte>

When this method returns true, the byte array segment from which this stream was created; when this method returns false, this parameter is set to default.

Returns

true if the buffer is exposable; otherwise, false.

Remarks

This method returns true when the underlying buffer is marked as exposable, which happens when the current MemoryStream instance is created with:

The underlying buffer will not be exposed if the current MemoryStream instance is created with:

Note

This method works when the memory stream is closed.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0