StreamReader.Read Method (Char, Int32, Int32)
Reads a specified maximum of characters from the current stream into a buffer, beginning at the specified index.
Assembly: mscorlib (in mscorlib.dll)
abstract Read : buffer:char byref * index:int * count:int -> int override Read : buffer:char byref * index:int * count:int -> int
- Type: System.Char
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.
- Type: System.Int32
The index of buffer at which to begin writing.
- Type: System.Int32
The maximum number of characters to read.
Return ValueType: System.Int32
The number of characters that have been read, or 0 if at the end of the stream and no data was read. The number will be less than or equal to the count parameter, depending on whether the data is available within the stream.
This method overrides TextReader.Read.
This method returns an integer so that it can return 0 if the end of the stream has been reached.
When using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream, where the internal buffer is set to your desired block size, and to always read less than the block size. If the size of the internal buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes). If you manipulate the position of the underlying stream after reading data into the buffer, the position of the underlying stream might not match the position of the internal buffer. To reset the internal buffer, call the DiscardBufferedData method; however, this method slows performance and should be called only when absolutely necessary.
For a list of common I/O tasks, see Common I/O Tasks.
.NET FrameworkSupported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.