System.IO.StreamReader.Peek Method

Returns the next available character but does not consume it.

Syntax

public override int Peek ()

Returns

An integer representing the next character to be read, or -1 if there are no characters to be read or if the stream does not support seeking.

Exceptions

TypeReason
System.IO.IOExceptionAn I/O error occurred.

Remarks

The StreamReader.Peek method returns an integer value in order to determine whether the end of the file, or another error has occurred. This allows a user to first check if the returned value is -1 before casting it to a char type.

This method overrides TextReader.Peek.

The current position of the System.IO.StreamReader object is not changed by StreamReader.Peek.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0