Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​IO.​BinaryReader

Assembly: System.Runtime

Inheritance: object → BinaryReader

Implemented Interfaces

Reads primitive data types as binary values in a specific encoding.

Properties

public Stream
BaseStream
Exposes access to the underlying stream of the <see cref="T:System.IO.BinaryReader" /> .

Methods

public void
Close​()
Closes the current reader and the underlying stream.
public void
Dispose​()
Releases all resources used by the current instance of the <see cref="T:System.IO.BinaryReader" /> class.
protected void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.IO.BinaryReader" /> class and optionally releases the managed resources.
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
protected void
FillBuffer​(int numBytes)
Fills the internal buffer with the specified number of bytes read from the stream.
numBytes The number of bytes to be read.
public int
PeekChar​()
Returns the next available character and does not advance the byte or character position.
Returns The next available character, or -1 if no more characters are available or the stream does not support seeking.
public int
Read​()
Reads characters from the underlying stream and advances the current position of the stream in accordance with the <see langword="Encoding" /> used and the specific character being read from the stream.
Returns The next character from the input stream, or -1 if no characters are currently available.
public int
Read​(byte[] buffer, int index, int count)
Reads the specified number of bytes from the stream, starting from a specified point in the byte array.
Returns The number of bytes read into <paramref name="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.
buffer The buffer to read data into.
index The starting point in the buffer at which to begin reading into the buffer.
count The number of bytes to read.
public int
Read​(char[] buffer, int index, int count)
Reads the specified number of characters from the stream, starting from a specified point in the character array.
Returns The total number of characters read into the buffer. This might be less than the number of characters requested if that many characters are not currently available, or it might be zero if the end of the stream is reached.
buffer The buffer to read data into.
index The starting point in the buffer at which to begin reading into the buffer.
count The number of characters to read.
public int
Read​(Span<​byte> buffer)
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Returns The total number of bytes read into the buffer. This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
buffer A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.
public int
Read​(Span<​char> buffer)
Reads, from the current stream, the same number of characters as the length of the provided buffer, writes them in the provided buffer, and advances the current position in accordance with the <see langword="Encoding" /> used and the specific character being read from the stream.
Returns The total number of characters read into the buffer. This might be less than the number of characters requested if that many characters are not currently available, or it might be zero if the end of the stream is reached.
buffer A span of characters. When this method returns, the contents of this region are replaced by the characters read from the current source.
public int
Read7BitEncodedInt​()
Reads in a 32-bit integer in compressed format.
Returns A 32-bit integer in compressed format.
public long
Read7BitEncodedInt64​()
Reads a number 7 bits at a time.
Returns The number that is read from this binary reader instance.
public bool
ReadBoolean​()
Reads a <see langword="Boolean" /> value from the current stream and advances the current position of the stream by one byte.
Returns <see langword="true" /> if the byte is nonzero; otherwise, <see langword="false" /> .
public byte
ReadByte​()
Reads the next byte from the current stream and advances the current position of the stream by one byte.
Returns The next byte read from the current stream.
public byte[]
ReadBytes​(int count)
Reads the specified number of bytes from the current stream into a byte array and advances the current position by that number of bytes.
Returns A byte array containing data read from the underlying stream. This might be less than the number of bytes requested if the end of the stream is reached.
count The number of bytes to read. This value must be 0 or a non-negative number or an exception will occur.
public char
ReadChar​()
Reads the next character from the current stream and advances the current position of the stream in accordance with the <see langword="Encoding" /> used and the specific character being read from the stream.
Returns A character read from the current stream.
public char[]
ReadChars​(int count)
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 <see langword="Encoding" /> used and the specific character being read from the stream.
Returns A character array containing data read from the underlying stream. This might be less than the number of characters requested if the end of the stream is reached.
count The number of characters to read.
public decimal
ReadDecimal​()
Reads a decimal value from the current stream and advances the current position of the stream by sixteen bytes.
Returns A decimal value read from the current stream.
public double
ReadDouble​()
Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes.
Returns An 8-byte floating point value read from the current stream.
public void
ReadExactly​(Span<​byte> buffer)
Reads bytes from the current stream and advances the position within the stream until the <paramref name="buffer" /> is filled.
buffer A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current stream.
public Half
ReadHalf​()
Reads a 2-byte floating point value from the current stream and advances the current position of the stream by two bytes.
Returns A 2-byte floating point value read from the current stream.
public short
ReadInt16​()
Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes.
Returns A 2-byte signed integer read from the current stream.
public int
ReadInt32​()
Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.
Returns A 4-byte signed integer read from the current stream.
public long
ReadInt64​()
Reads an 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes.
Returns An 8-byte signed integer read from the current stream.
public sbyte
ReadSByte​()
Reads a signed byte from this stream and advances the current position of the stream by one byte.
Returns A signed byte read from the current stream.
public Single
ReadSingle​()
Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.
Returns A 4-byte floating point value read from the current stream.
public string
ReadString​()
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.
Returns The string being read.
public ushort
ReadUInt16​()
Reads a 2-byte unsigned integer from the current stream using little-endian encoding and advances the position of the stream by two bytes.
Returns A 2-byte unsigned integer read from this stream.
public uint
ReadUInt32​()
Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes.
Returns A 4-byte unsigned integer read from this stream.
public ulong
ReadUInt64​()
Reads an 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes.
Returns An 8-byte unsigned integer read from this stream.
public bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj The object to compare with the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.