Export (0) Print
Expand All

MemoryStream.ToArray Method

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

Namespace:  System.IO
Assemblies:   mscorlib (in mscorlib.dll)
  System.IO (in System.IO.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.

NoteNote

This method works when the MemoryStream is closed.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft