Reads the specified number of characters from the current stream, returns the data in a character array, and advances the current position in accordance with the Encoding used and the specific character being read from the stream.

The BinaryReader class provides methods that simplify reading primitive data types from a stream. For example, you can use the
ReadBoolean method to read the next byte as a Boolean value and advance the current position in the stream by one byte. The class includes read methods that support different data types.

When you create a new instance of the BinaryReader class, you provide the stream to read from, and optionally specify the type of encoding and whether to leave the stream open after disposing the BinaryReader object. If you do not specify an encoding type, UTF-8 is used.

Important

This type implements the
IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its
Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the
IDisposable interface topic.