System.IO.StringReader.Read Method

Reads a block of characters from the input string and advances the character position by count.

Syntax

public override int Read (char[] buffer, int index, int count)

Parameters

buffer
When this method returns, contains the specified character array with the values between index and (index + count - 1) replaced by the characters read from the current source.
index
The starting index in the buffer.
count
The number of characters to read.

Returns

The total number of characters read into the buffer. This can be less than the number of characters requested if that many characters are not currently available, or zero if the end of the underlying string has been reached.

Exceptions

TypeReason
ArgumentNullException buffer is null.
ArgumentException(index + count ) > buffer.Length.
ArgumentOutOfRangeException

index < 0

- or-

count < 0.

ObjectDisposedExceptionThe current reader is closed.

Remarks

This method overrides TextReader.Read.

The method will read up to count characters from the System.IO.StringReader into the buffer character array starting at position index. Returns the actual number of characters read, or zero if the end of the string has been reached and no characters are read.

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>]

Append text to a file.

[<topic://cpconopeningappendingtologfile>]

File.AppendText(string)

FileInfo.AppendText

Get the size of a file.

FileInfo.Length

Get the attributes of a file.

File.GetAttributes(string)

Set the attributes of a file.

File.SetAttributes(string, FileAttributes)

Determine if a file exists.

File.Exists(string)

Read from a binary file.

[<topic://cpconReadingWritingToNewlyCreatedDataFile>]

Write to a binary file.

[<topic://cpconReadingWritingToNewlyCreatedDataFile>]

Requirements

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