C# BinaryWriter Write(Int16)

Description

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

Syntax

BinaryWriter.Write(Int16) has the following syntax.


public virtual void Write(
  short value
)

Parameters

BinaryWriter.Write(Int16) has the following parameters.

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

Returns

BinaryWriter.Write(Int16) method returns

Example


using System;//from  w ww  .  ja  v a2s . c  o 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((Int16)2);
        }

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

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