This documentation is archived and is not being maintained.

TextReader.ReadBlock Method

Reads a maximum of count characters from the current stream and writes the data to buffer, beginning at index.

[Visual Basic]
Public Overridable Function ReadBlock( _
   <InteropServices.In(), _
   Out()> ByVal buffer() As Char, _
   ByVal index As Integer, _
   ByVal count As Integer _
) As Integer
public virtual int ReadBlock(
] char[] buffer,
 int index,
 int count
public: virtual int ReadBlock(
] __wchar_t buffer __gc[],
 int index,
 int count
public function ReadBlock(
   buffer : Char[],
 index : int,
 count : int
) : int;


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

Return Value

The number of characters that have been read. The number will be less than or equal to count, depending on whether all input characters have been read.


Exception Type Condition
ArgumentNullException buffer is a null reference (Nothing in Visual Basic).
ArgumentException The buffer length minus index is less than count.
ArgumentOutOfRangeException index or count is negative.
ObjectDisposedException The TextReader is closed.
IOException An I/O error occurs.


The method blocks until either count characters are read, or all characters have been read. This is a blocking version of Read.

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

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Append text to a file. Opening and Appending to a Log File



Get the size of a file. FileInfo.Length
Get the attributes of a file. File.GetAttributes
Set the attributes of a file. File.SetAttributes
Determine if a file exists. File.Exists
Read from a binary file. Reading and Writing to a Newly Created Data File
Write to a binary file. Reading and Writing to a Newly Created Data File


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

TextReader Class | TextReader Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File