Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

BinaryReader::Read Method (array<Byte>^, Int32, Int32)


Reads the specified number of bytes from the stream, starting from a specified point in the byte array.

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

virtual int Read(
	array<unsigned char>^ buffer,
	int index,
	int count


Type: array<System::Byte>^

The buffer to read data into.

Type: System::Int32

The starting point in the buffer at which to begin reading into the buffer.

Type: System::Int32

The number of bytes to read.

Return Value

Type: System::Int32

The number of bytes read into buffer. This might be less than the number of bytes requested if that many bytes are not available, or it might be zero if the end of the stream is reached.

Exception Condition

The buffer length minus index is less than count.


The number of decoded characters to read is greater than count. This can happen if a Unicode decoder returns fallback characters or a surrogate pair.


buffer is null.


index or count is negative.


The stream is closed.


An I/O error occurs.

BinaryReader does not restore the file position after an unsuccessful read operation.

For a list of common I/O tasks, see Common I/O Tasks.

The following example shows how to write binary data by using memory as a backing store. It displays a message to the console that indicates whether the data was written correctly.

No code example is currently available or this language may not be supported.

This example reads the contents of a file and displays each byte's numeric value in 16-column format. The end of the file that is being read is detected when the Read method returns zero bytes.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.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
© 2016 Microsoft