ToArray Method

MemoryStream.ToArray Method ()


Writes the stream contents to a byte array, regardless of the Position property.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

public virtual byte[] ToArray()

Return Value

Type: System.Byte[]

A new byte array.

This method omits unused bytes in MemoryStream from the array. To get the entire buffer, use the GetBuffer method.

This method returns a copy of the contents of the MemoryStream as a byte array. If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned. See the MemoryStream constructor for details.


This method works when the MemoryStream is closed.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft