Dark Mode
Image

C# Properties

C# Inheritance

C# Polymorphism

C# Strings

C# Generics

C# Delegates

C# Reflection

Anonymous Function

C# Multithreading

C# Synchronization

C# Web Service

C# Misc

C# New Features

C# Programs

ADO.NET Tutorial

ASP.NET Tutorial

C# BinaryWriter

 

C# BinaryWriter class is used to write binary information into stream. It is found in System.IO namespace. It also supports writing string in specific encoding.

C# BinaryWriter Example

Let's see the simple example of BinaryWriter class which writes data into dat file.
using System;  
using System.IO;  
namespace BinaryWriterExample  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            string fileName = "e:\\binaryfile.dat";  
            using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))  
            {  
                writer.Write(2.5);  
                writer.Write("this is string data");  
                writer.Write(true);  
            }  
            Console.WriteLine("Data written successfully...");    
        }  
    }  
}  

Output:

Data written successfully...

 

Comment / Reply From