Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.