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

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)
disposing <see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
Releases the unmanaged resources used by the <see cref="T:System.IO.BinaryReader" /> class and optionally releases the managed resources.
protected void
FillBuffer​(int numBytes)
numBytes The number of bytes to be read.
Fills the internal buffer with the specified number of bytes read from the stream.
public int
PeekChar​()
Returns The next available character, or -1 if no more characters are available or the stream does not support seeking.
Returns the next available character and does not advance the byte or character position.
public int
Read​()
Returns The next character from the input stream, or -1 if no characters are currently available.
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.
public int
Read​(byte[] buffer, int index, int count)
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.
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.
Reads the specified number of bytes from the stream, starting from a specified point in the byte array.
public int
Read​(char[] buffer, int index, int count)
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.
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.
Reads the specified number of characters from the stream, starting from a specified point in the character array.
public int
Read​(Span`1 buffer)
public int
Read​(Span`1 buffer)
public int
Read7BitEncodedInt​()
Returns A 32-bit integer in compressed format.
Reads in a 32-bit integer in compressed format.
public long
Read7BitEncodedInt64​()
Returns The number that is read from this binary reader instance.
Reads a number 7 bits at a time.
public bool
ReadBoolean​()
Returns <see langword="true" /> if the byte is nonzero; otherwise, <see langword="false" /> .
Reads a <see langword="Boolean" /> value from the current stream and advances the current position of the stream by one byte.
public byte
ReadByte​()
Returns The next byte read from the current stream.
Reads the next byte from the current stream and advances the current position of the stream by one byte.
public byte[]
ReadBytes​(int count)
count The number of bytes to read. This value must be 0 or a non-negative number or an exception will occur.
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.
Reads the specified number of bytes from the current stream into a byte array and advances the current position by that number of bytes.
public char
ReadChar​()
Returns A character read from the current stream.
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.
public char[]
ReadChars​(int count)
count The number of characters to read.
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.
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.
public decimal
ReadDecimal​()
Returns A decimal value read from the current stream.
Reads a decimal value from the current stream and advances the current position of the stream by sixteen bytes.
public double
ReadDouble​()
Returns An 8-byte floating point value read from the current stream.
Reads an 8-byte floating point value from the current stream and advances the current position of the stream by eight bytes.
public void
ReadExactly​(Span`1 buffer)
public Half
ReadHalf​()
Returns A 2-byte floating point value read from the current stream.
Reads a 2-byte floating point value from the current stream and advances the current position of the stream by two bytes.
public short
ReadInt16​()
Returns A 2-byte signed integer read from the current stream.
Reads a 2-byte signed integer from the current stream and advances the current position of the stream by two bytes.
public int
ReadInt32​()
Returns A 4-byte signed integer read from the current stream.
Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.
public long
ReadInt64​()
Returns An 8-byte signed integer read from the current stream.
Reads an 8-byte signed integer from the current stream and advances the current position of the stream by eight bytes.
public sbyte
ReadSByte​()
Returns A signed byte read from the current stream.
Reads a signed byte from this stream and advances the current position of the stream by one byte.
public Single
ReadSingle​()
Returns A 4-byte floating point value read from the current stream.
Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes.
public string
ReadString​()
Returns The string being read.
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.
public ushort
ReadUInt16​()
Returns A 2-byte unsigned integer read from this stream.
Reads a 2-byte unsigned integer from the current stream using little-endian encoding and advances the position of the stream by two bytes.
public uint
ReadUInt32​()
Returns A 4-byte unsigned integer read from this stream.
Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by four bytes.
public ulong
ReadUInt64​()
Returns An 8-byte unsigned integer read from this stream.
Reads an 8-byte unsigned integer from the current stream and advances the position of the stream by eight bytes.
public bool
Equals​(object obj)
Inherited from object
obj The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to 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
Returns A hash code for the current object.
Serves as the default hash function.
public Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates 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.