C# BinaryWriter Write(Int32)

Description

BinaryWriter Write(Int32) Writes a four-byte signed integer to the current stream and advances the stream position by four bytes.

Syntax

BinaryWriter.Write(Int32) has the following syntax.


public virtual void Write(
  int value
)

Parameters

BinaryWriter.Write(Int32) has the following parameters.

  • value - The four-byte signed integer to write.

Returns

BinaryWriter.Write(Int32) method returns

Example


using System;/*from w ww.ja v  a2 s  .co m*/
using System.IO;

class ConsoleApplication
{
    const string fileName = "data.dat";

    static void Main()
    {

        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
        {
            writer.Write((Int32)2);
        }

        using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
        {
            Console.WriteLine(reader.ReadInt32());
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter