C# BinaryReader ReadInt16
Description
BinaryReader ReadInt16
Reads a 2-byte signed integer
from the current stream and advances the current position of the stream by
two bytes.
Syntax
BinaryReader.ReadInt16
has the following syntax.
public virtual short ReadInt16()
Returns
BinaryReader.ReadInt16
method returns A 2-byte signed integer read from the current stream.
Example
/*from w w w . j a va 2 s . c o m*/
using System;
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.