TextReader.ReadBlock 方法

定义

重载

ReadBlock(Span<Char>)

从当前流中读取字符并将数据写入缓冲区。Reads the characters from the current stream and writes the data to a buffer.

ReadBlock(Char[], Int32, Int32)

从当前文本读取器中读取指定的最大字符数并从指定索引处开始将该数据写入缓冲区。Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.

ReadBlock(Span<Char>)

从当前流中读取字符并将数据写入缓冲区。Reads the characters from the current stream and writes the data to a buffer.

public:
 virtual int ReadBlock(Span<char> buffer);
public virtual int ReadBlock (Span<char> buffer);
abstract member ReadBlock : Span<char> -> int
override this.ReadBlock : Span<char> -> int
Public Overridable Function ReadBlock (buffer As Span(Of Char)) As Integer

参数

buffer
Span<Char>

此方法返回时,包含指定的字符范围,这些字符由从当前源中读取的字符替换。When this method returns, contains the specified span of characters replaced by the characters read from the current source.

返回

Int32

已读取的字符数。The number of characters that have been read. 该数字将小于或等于 buffer 长度,具体取决于是否已读取所有输入字符。The number will be less than or equal to the buffer length, depending on whether all input characters have been read.

例外

buffernullbuffer is null.

StreamReader 是关闭的。The StreamReader is closed.

出现 I/O 错误。An I/O error occurred.

适用于

ReadBlock(Char[], Int32, Int32)

从当前文本读取器中读取指定的最大字符数并从指定索引处开始将该数据写入缓冲区。Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.

public:
 virtual int ReadBlock(cli::array <char> ^ buffer, int index, int count);
public virtual int ReadBlock (char[] buffer, int index, int count);
abstract member ReadBlock : char[] * int * int -> int
override this.ReadBlock : char[] * int * int -> int
Public Overridable Function ReadBlock (buffer As Char(), index As Integer, count As Integer) As Integer

参数

buffer
Char[]

当此方法返回时,此参数包含指定的字符数组,此数组中 index 和 (index + count - 1) 之间的值被从当前源中读取的字符所替换。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
Int32

buffer 中开始写入的位置。The position in buffer at which to begin writing.

count
Int32

最多读取的字符数。The maximum number of characters to read.

返回

Int32

已读取的字符数。The number of characters that have been read. 该数字将小于或等于 count,取决于是否所有的输入字符都已读取。The number will be less than or equal to count, depending on whether all input characters have been read.

例外

buffernullbuffer is null.

缓冲区长度减去 index 小于 countThe buffer length minus index is less than count.

indexcount 为负数。index or count is negative.

TextReader 是关闭的。The TextReader is closed.

出现 I/O 错误。An I/O error occurs.

注解

基础文本读取器的位置由读入的字符数来提前 bufferThe position of the underlying text reader is advanced by the number of characters that were read into buffer.

方法会一直阻止 count ,直到读取或读取了所有字符。The method blocks until either count characters are read, or all characters have been read. 这是的一个阻止版 ReadThis is a blocking version of Read.

另请参阅

适用于