System.IO.StringReader.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 no more characters are available or the stream does not support seeking.

Exceptions

TypeReason
ObjectDisposedExceptionThe current reader is closed.

Remarks

The StringReader.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 the TextReader.Peek method.

The current position of the StringReader is not changed by this operation.

The following table lists examples of other typical or related I/O tasks.

Create a text file.

[<topic://cpconwritingtexttofile>]

Write to a text file.

[<topic://cpconwritingtexttofile>]

Read from a text file.

[<topic://cpconreadingtextfromfile>]

Get the size of a file.

FileInfo.Length

Requirements

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