This documentation is archived and is not being maintained.

MemoryStream.GetBuffer Method

Returns the array of unsigned bytes from which this stream was created.

[Visual Basic]
Public Overridable Function GetBuffer() As Byte()
[C#]
public virtual byte[] GetBuffer();
[C++]
public: virtual unsigned char GetBuffer()  __gc[];
[JScript]
public function GetBuffer() : Byte[];

Return Value

The byte array from which this stream was created, or the underlying array if a byte array was not provided to the MemoryStream constructor during construction of the current instance.

Exceptions

Exception Type Condition
UnauthorizedAccessException The MemoryStream instance was not created with a publicly visible buffer.

Remarks

For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

To create a MemoryStream instance with a publicly visible buffer, use MemoryStream(), MemoryStream(Byte[], Int32, Int32, Boolean, Boolean), or MemoryStream(Int32). If the current stream is resizable, two calls to this method do not return the same array if the underlying byte array is resized between calls. For additional information, see Capacity.

Note   This method works when the memory stream is closed.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

MemoryStream Class | MemoryStream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

Show: