C# BinaryReader ReadInt32

Description

BinaryReader ReadInt32 Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes.

Syntax

BinaryReader.ReadInt32 has the following syntax.


public virtual int ReadInt32()

Returns

BinaryReader.ReadInt32 method returns A 4-byte signed integer read from the current stream.

Example

The following code example demonstrates how to store and retrieve application settings in a file.


//  w  w  w. ja  v a  2 s  .  co  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(10);
        }
        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