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

Implemented Interfaces

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)
Releases the unmanaged resources used by the <see cref="T:System.IO.BinaryWriter" /> 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.
DisposeAsync​()
Asynchronously releases all resources used by the current instance of the <see cref="T:System.IO.BinaryWriter" /> class.
Returns A task that represents the asynchronous dispose operation.
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)
Sets the position within the current stream.
Returns The position with the current stream.
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.
public void
Write​(bool value)
Writes a one-byte <see langword="Boolean" /> value to the current stream, with 0 representing <see langword="false" /> and 1 representing <see langword="true" /> .
value The <see langword="Boolean" /> value to write (0 or 1).
public void
Write​(byte value)
Writes an unsigned byte to the current stream and advances the stream position by one byte.
value The unsigned byte to write.
public void
Write​(byte[] buffer)
Writes a byte array to the underlying stream.
buffer A byte array containing the data to write.
public void
Write​(byte[] buffer, int index, int count)
Writes a region of a byte array to the current stream.
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.
public void
Write​(char ch)
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.
ch The non-surrogate, Unicode character to write.
public void
Write​(char[] chars)
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.
chars A character array containing the data to write.
public void
Write​(char[] chars, int index, int count)
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.
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.
public void
Write​(decimal value)
Writes a decimal value to the current stream and advances the stream position by sixteen bytes.
value The decimal value to write.
public void
Write​(double value)
Writes an eight-byte floating-point value to the current stream and advances the stream position by eight bytes.
value The eight-byte floating-point value to write.
public void
Write​(Half value)
Writes a two-byte floating-point value to the current stream and advances the stream position by two bytes.
value The two-byte floating-point value to write.
public void
Write​(short value)
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
value The two-byte signed integer to write.
public void
Write​(int value)
Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.
value The four-byte signed integer to write.
public void
Write​(long value)
Writes an eight-byte signed integer to the current stream and advances the stream position by eight bytes.
value The eight-byte signed integer to write.
public void
Write​(ReadOnlySpan<​byte> buffer)
Writes a span of bytes to the current stream.
buffer The span of bytes to write.
public void
Write​(ReadOnlySpan<​char> chars)
Writes a span of characters 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.
chars A span of chars to write.
public void
Write​(sbyte value)
Writes a signed byte to the current stream and advances the stream position by one byte.
value The signed byte to write.
public void
Write​(Single value)
Writes a four-byte floating-point value to the current stream and advances the stream position by four bytes.
value The four-byte floating-point value to write.
public void
Write​(string value)
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.
value The value to write.
public void
Write​(ushort value)
Writes a two-byte unsigned integer to the current stream and advances the stream position by two bytes.
value The two-byte unsigned integer to write.
public void
Write​(uint value)
Writes a four-byte unsigned integer to the current stream and advances the stream position by four bytes.
value The four-byte unsigned integer to write.
public void
Write​(ulong value)
Writes an eight-byte unsigned integer to the current stream and advances the stream position by eight bytes.
value The eight-byte unsigned integer to write.
public void
Write7BitEncodedInt​(int value)
Writes a 32-bit integer in a compressed format.
value The 32-bit integer to be written.
public void
Write7BitEncodedInt64​(long value)
Writes out a number 7 bits at a time.
value The value to write.
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.