C# Program to Demonstrate Binary Writer

This is a C# Program to illustrate binary writer.

Problem Description

This C# Program Illustrates Binary Writer.

Problem Solution

Here Write method writes a Boolean value to the stream as a one-byte value.

Program/Source Code

Here is source code of the C# Program to Illustrate Binary Writer. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Illustrate Binary Writer
 */
using System;
using System.IO;
class ConsoleApplication
{
    const string fileName = "program.dat";
    static void Main()
    {
       Write();
       Console.WriteLine("Using Binary Writer Class the Contents are Written ");
    }
    public static void Write()
    {
        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, 
                                                      FileMode.Create)))
        {
            writer.Write(1.250F);
            writer.Write(@"c:\Temp");
        }
    }
}
Program Explanation

This C# program is used to illustrate binary writer. Using binary writer class the contents are written in the file. The BinaryWriter class provides methods that simplify writing primitive data types to a stream. The write() method is used to write a Boolean value to the stream as a one-byte value.

advertisement
advertisement

The class includes write methods that support different data types while creating a new instance of the BinaryWriter class. Provide the stream to write to, and optionally specify the type of encoding and whether to leave the stream open after disposing the BinaryWriter object. If the encoding type didn’t specified, UTF-8 is used.

Runtime Test Cases
 
Using Binary Writer Class the Contents are Written

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.