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 [C#] public virtual int ReadBlock( [ In, Out ] char[] buffer, int index, int count ); [C++] public: virtual int ReadBlock( [ In, Out ] __wchar_t buffer __gc[], int index, int count ); [JScript] public function ReadBlock( buffer : Char[], index : int, count : int ) : int;
Parameters
- buffer
- 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.
- index
- The place in buffer at which to begin writing.
- count
- 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.
Exceptions
| 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. |
Remarks
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 |
Requirements
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