C# BinaryReader ReadChar

Description

BinaryReader ReadChar Reads the next character from the current stream and advances the current position of the stream in accordance with the Encoding used and the specific character being read from the stream.

Syntax

BinaryReader.ReadChar has the following syntax.


public virtual char ReadChar()

Returns

BinaryReader.ReadChar method returns A character read from the current stream.

Example


using System;/* ww w .  java  2s.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('c');
        }

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

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