Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

BinaryWriter Constructor

.NET Framework 1.1

Initializes a new instance of the BinaryWriter class that writes to a stream.

Overload List

Initializes a new instance of the BinaryWriter class that writes to a stream.

Supported by the .NET Compact Framework.

[Visual Basic] Protected Sub New()
[C#] protected BinaryWriter();
[C++] protected: BinaryWriter();
[JScript] protected function BinaryWriter();

Initializes a new instance of the BinaryWriter class based on the supplied stream and using UTF-8 as the encoding for strings.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Stream)
[C#] public BinaryWriter(Stream);
[C++] public: BinaryWriter(Stream*);
[JScript] public function BinaryWriter(Stream);

Initializes a new instance of the BinaryWriter class based on the supplied stream and a specific character encoding.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(Stream, Encoding)
[C#] public BinaryWriter(Stream, Encoding);
[C++] public: BinaryWriter(Stream*, Encoding*);
[JScript] public function BinaryWriter(Stream, Encoding);

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for the BinaryWriter class.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the BinaryWriter constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim binWriter As New BinaryWriter( _
    File.Open(fileName, FileMode.Create))
Try
    binWriter.Write(aspRatio)
    binWriter.Write(lkupDir)
    binWriter.Write(saveTime)
    binWriter.Write(statusBar)
Finally
    binWriter.Close()
End Try

[C#] 
using(BinaryWriter binWriter = 
    new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
    binWriter.Write(aspectRatio);
    binWriter.Write(lookupDir);
    binWriter.Write(autoSaveTime);
    binWriter.Write(showStatusBar);
}

[C++] 
BinaryWriter* binWriter = 
    new BinaryWriter(File::Open(fileName, FileMode::Create));
try
{
    binWriter->Write(aspectRatio);
    binWriter->Write(lookupDir);
    binWriter->Write(autoSaveTime);
    binWriter->Write(showStatusBar);
}
__finally
{
    binWriter->Close();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

BinaryWriter Class | BinaryWriter Members | System.IO Namespace

Show:
© 2015 Microsoft