RecyclableMemoryStream.ToArray method

October 6, 2021 · View on GitHub

Returns a new array with a copy of the buffer's contents. You should almost certainly be using GetBuffer combined with the Length to access the bytes in this stream. Calling ToArray will destroy the benefits of pooled buffers, but it is included for the sake of completeness.

[Obsolete("This method has degraded performance vs. GetBuffer and should be avoided.")]
public override byte[] ToArray()

Exceptions

exceptioncondition
ObjectDisposedExceptionObject has been disposed.
NotSupportedExceptionThe current RecyclableMemoryStreamManagerobject disallows ToArray calls.
OutOfMemoryExceptionThe length of the stream is too long for a contiguous array.

See Also