Users Online

· Guests Online: 91

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate Binary Writer

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.

 

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

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.67 seconds
10,834,277 unique visits