← Interactive API Explorer
Namespace: System.IO

BinaryWriter

Writes primitive types in binary to a stream and supports writing strings in a specific encoding.

Properties (1)

Stream BaseStream
Gets the underlying stream of the BinaryWriter.
Value: The underlying stream associated with the BinaryWriter.

Methods (14)

BinaryWriter(IO.Stream,Text.Encoding,Boolean)Constructor
Initializes a new instance of the BinaryWriter class based on the specified stream and character encoding, and optionally leaves the stream open.
ParameterDescription
outputThe output stream.
encodingThe character encoding to use.
leaveOpentrue to leave the stream open after the BinaryWriter object is disposed; otherwise, false.
BinaryWriter(IO.Stream)Constructor
Initializes a new instance of the BinaryWriter class based on the specified stream and using UTF-8 encoding.
ParameterDescription
outputThe output stream.
void Write(Boolean)
Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing true.
ParameterDescription
valueThe Boolean value to write (0 or 1).
void Write(Byte)
Writes an unsigned byte to the current stream and advances the stream position by one byte.
ParameterDescription
valueThe unsigned byte to write.
void Write(Int16)
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
ParameterDescription
valueThe two-byte signed integer to write.
void Write(UInt16)
Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.
ParameterDescription
valueThe two-byte unsigned integer to write.
void Write(Int32)
Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.
ParameterDescription
valueThe four-byte signed integer to write.
void Write(UInt32)
Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.
ParameterDescription
valueThe four-byte unsigned integer to write.
void Write(Int64)
Writes an eight-byte signed integer to the current stream and advances the stream position by eight bytes.
ParameterDescription
valueThe eight-byte signed integer to write.
void Write(UInt64)
Writes an eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.
ParameterDescription
valueThe eight-byte unsigned integer to write.
void Write(Single)
Writes a four-byte floating-point value to the current stream and advances the stream position by four bytes.
ParameterDescription
valueThe four-byte floating-point value to write.
void Write(Double)
Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes.
ParameterDescription
valueThe eight-byte floating-point value to write.
void Write(String)
Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter, and advances the current position of the stream in accordance with the encoding used and the specific characters being written to the stream.
ParameterDescription
valueThe value to write.
void Close
Closes the current BinaryWriter and the underlying stream.