C# BinaryReader PeekChar

Description

BinaryReader PeekChar Returns the next available character and does not advance the byte or character position.

Syntax

BinaryReader.PeekChar has the following syntax.


public virtual int PeekChar()

Returns

BinaryReader.PeekChar method returns The next available character, or -1 if no more characters are available or the stream does not support seeking.

Example


using System;/*www .ja v  a  2 s  . co  m*/
using System.IO;

class BinaryRW
{
    static void Main()
    {
        int i = 0;
        char[] myChars = new char[]{'a','v','c','d'};
        MemoryStream memStream = new MemoryStream();
        BinaryWriter binWriter = new BinaryWriter(memStream);

        for(i = 0; i < myChars.Length; i++)
        {
            binWriter.Write(myChars[i]);
        }

        BinaryReader binReader = new BinaryReader(memStream);

        Console.Write(binReader.PeekChar());

    }
}

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