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.​BinaryWriter

Assembly: System.Runtime

Inheritance: object → BinaryWriter

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

Fields and Constants

public static readonly BinaryWriter
Null
Specifies a <see cref="T:System.IO.BinaryWriter" /> with no backing store.
protected Stream
OutStream
Holds the underlying stream.

Properties

public Stream
BaseStream
Gets the underlying stream of the <see cref="T:System.IO.BinaryWriter" /> .

Methods

public void
Close​()
Closes the current <see cref="T:System.IO.BinaryWriter" /> and the underlying stream.
public void
Dispose​()
Releases all resources used by the current instance of the <see cref="T:System.IO.BinaryWriter" /> 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.BinaryWriter" /> and optionally releases the managed resources.
DisposeAsync​()
Returns A task that represents the asynchronous dispose operation.
Asynchronously releases all resources used by the current instance of the <see cref="T:System.IO.BinaryWriter" /> class.
public void
Flush​()
Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
public long
Seek​(int offset, SeekOrigin origin)
offset A byte offset relative to <paramref name="origin" /> .
origin A field of <see cref="T:System.IO.SeekOrigin" /> indicating the reference point from which the new position is to be obtained.
Returns The position with the current stream.
Sets the position within the current stream.
public void
Write​(bool value)
value The <see langword="Boolean" /> value to write (0 or 1).
Writes a one-byte <see langword="Boolean" /> value to the current stream, with 0 representing <see langword="false" /> and 1 representing <see langword="true" /> .
public void
Write​(byte value)
value The unsigned byte to write.
Writes an unsigned byte to the current stream and advances the stream position by one byte.
public void
Write​(byte[] buffer)
buffer A byte array containing the data to write.
Writes a byte array to the underlying stream.
public void
Write​(byte[] buffer, int index, int count)
buffer A byte array containing the data to write.
index The index of the first byte to read from <paramref name="buffer" /> and to write to the stream.
count The number of bytes to read from <paramref name="buffer" /> and to write to the stream.
Writes a region of a byte array to the current stream.
public void
Write​(char ch)
ch The non-surrogate, Unicode character to write.
Writes a Unicode character to the current stream and advances the current position of the stream in accordance with the <see langword="Encoding" /> used and the specific characters being written to the stream.
public void
Write​(char[] chars)
chars A character array containing the data to write.
Writes a character array to the current stream and advances the current position of the stream in accordance with the <see langword="Encoding" /> used and the specific characters being written to the stream.
public void
Write​(char[] chars, int index, int count)
chars A character array containing the data to write.
index The index of the first character to read from <paramref name="chars" /> and to write to the stream.
count The number of characters to read from <paramref name="chars" /> and to write to the stream.
Writes a section of a character array to the current stream, and advances the current position of the stream in accordance with the <see langword="Encoding" /> used and perhaps the specific characters being written to the stream.
public void
Write​(decimal value)
value The decimal value to write.
Writes a decimal value to the current stream and advances the stream position by sixteen bytes.
public void
Write​(double value)
value The eight-byte floating-point value to write.
Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes.
public void
Write​(Half value)
value The two-byte floating-point value to write.
Writes a two-byte floating-point value to the current stream and advances the stream position by two bytes.
public void
Write​(short value)
value The two-byte signed integer to write.
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
public void
Write​(int value)
value The four-byte signed integer to write.
Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.
public void
Write​(long value)
value The eight-byte signed integer to write.
Writes an eight-byte signed integer to the current stream and advances the stream position by eight bytes.
public void
Write​(ReadOnlySpan`1 buffer)
public void
Write​(ReadOnlySpan`1 chars)
public void
Write​(sbyte value)
value The signed byte to write.
Writes a signed byte to the current stream and advances the stream position by one byte.
public void
Write​(Single value)
value The four-byte floating-point value to write.
Writes a four-byte floating-point value to the current stream and advances the stream position by four bytes.
public void
Write​(string value)
value The value to write.
Writes a length-prefixed string to this stream in the current encoding of the <see cref="T:System.IO.BinaryWriter" /> , and advances the current position of the stream in accordance with the encoding used and the specific characters being written to the stream.
public void
Write​(ushort value)
value The two-byte unsigned integer to write.
Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.
public void
Write​(uint value)
value The four-byte unsigned integer to write.
Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.
public void
Write​(ulong value)
value The eight-byte unsigned integer to write.
Writes an eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.
public void
Write7BitEncodedInt​(int value)
value The 32-bit integer to be written.
Writes a 32-bit integer in a compressed format.
public void
Write7BitEncodedInt64​(long value)
value The value to write.
Writes out a number 7 bits at a time.
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.