This class complements BinaryReader. To
write binary data, simply call
Write( ) and pass data of the desired type; the
method is overloaded for all "primitive
types" (but not the generic
System.Object type—that is the subject of
the System.Runtime.Serialization namespaces). Be
aware, however, that because BinaryWriter is not the actual
destination of the data (the wrapped Stream object
is) the data may be cached in a buffer somewhere between the
BinaryWriter and the sink. To ensure data is
completely written, call the Flush( ) method. When
working with a BinaryWriter in a sensitive code
area, consider placing it in a using block to
ensure cleanup (in this case, release of the
Stream it wraps after flushing the data).
public class BinaryWriter : IDisposable {
// Public Constructors
public BinaryWriter(Stream output);
public BinaryWriter(Stream output,
System.Text.Encoding encoding);
// Protected Constructors
protected BinaryWriter( );
// Public Static Fields
public static readonly BinaryWriter Null;
// =System.IO.BinaryWriter
// Protected Instance Fields
protected Stream OutStream;
// Public Instance Properties
public virtual Stream BaseStream{get; }
// Public Instance Methods
public virtual void Close( );
public virtual void Flush( );
public virtual long Seek(int offset, SeekOrigin origin);
public virtual void Write(bool value);
public virtual void Write(byte value);
public virtual void Write(byte[ ] buffer);
public virtual void Write(byte[ ] buffer, int index, int count);
public virtual void Write(char ch);
public virtual void Write(char[ ] chars);
public virtual void Write(char[ ] chars, int index, int count);
public virtual void Write(decimal value);
public virtual void Write(double value);
public virtual void Write(short value);
public virtual void Write(int value);
public virtual void Write(long value);
public virtual void Write(sbyte value);
public virtual void Write(float value);
public virtual void Write(string value);
public virtual void Write(ushort value);
public virtual void Write(uint value);
public virtual void Write(ulong value);
// Protected Instance Methods
protected virtual void Dispose(bool disposing);
protected void Write7BitEncodedInt(int value);
}