Reader Level:

How to write a binary file in C#

By Mahesh Chand on July 12, 2012
How to write a binary file using C# and .NET.
  • 0
  • 0
  • 9783
Download Files:

Writing Binary to a Stream

The Write overloaded method is used to write primitive data types to a stream. The Write method can write a Boolean, Byte, Char, Decimal, Double, and Integer data types. 

The following code snippet creates a BinaryWriter and writes string, Boolean, integer and double data types to the stream. 

string authorName = "Mahesh Chand";
int age = 30;
string bookTitle = "ADO.NET Programming using C#";
bool mvp = true;
double price = 54.99;

using (BinaryWriter binWriter =
    new BinaryWriter(File.Open(fileName, FileMode.Create)))
    // Write string 
    // Write string 
    // Write integer
    // Write boolean
    // Write double 

Learn More: 

Mahesh Chand

Mahesh Chand is founder of C# Corner. C# Corner founded in 1999 is a FREE member contributions based open platform for developers to solve problems, learn new technology and hang out.  Mahesh has been awar... Read more


Trending up