TextReader.ReadAsync TextReader.ReadAsync TextReader.ReadAsync TextReader.ReadAsync Method

定义

重载

ReadAsync(Char[], Int32, Int32) ReadAsync(Char[], Int32, Int32) ReadAsync(Char[], Int32, Int32) ReadAsync(Char[], Int32, Int32)

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

ReadAsync(Memory<Char>, CancellationToken) ReadAsync(Memory<Char>, CancellationToken)

ReadAsync(Char[], Int32, Int32) ReadAsync(Char[], Int32, Int32) ReadAsync(Char[], Int32, Int32) ReadAsync(Char[], Int32, Int32)

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

public:
 virtual System::Threading::Tasks::Task<int> ^ ReadAsync(cli::array <char> ^ buffer, int index, int count);
[System.Runtime.InteropServices.ComVisible(false)]
public virtual System.Threading.Tasks.Task<int> ReadAsync (char[] buffer, int index, int count);
abstract member ReadAsync : char[] * int * int -> System.Threading.Tasks.Task<int>
override this.ReadAsync : char[] * int * int -> System.Threading.Tasks.Task<int>
Public Overridable Function ReadAsync (buffer As Char(), index As Integer, count As Integer) As Task(Of Integer)

参数

buffer
Char[]

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

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

count
Int32 Int32 Int32 Int32

最多读取的字符数。The maximum number of characters to read. 如果在将指定数量的字符读入缓冲区之前已到达文本的末尾,则当前方法将返回。If the end of the text is reached before the specified number of characters is read into the buffer, the current method returns.

返回

表示异步读取操作的任务。A task that represents the asynchronous read operation. TResult 参数的值包含读入缓冲区的总字节数。The value of the TResult parameter contains the total number of bytes read into the buffer. 如果当前可用字节数少于所请求的字节数,则该结果值可能小于所请求的字节数,或者如果已到达文本的末尾时,则为 0(零)。The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the text has been reached.

异常

indexcount 的总和大于缓冲区长度。The sum of index and count is larger than the buffer length.

文本读取器已被释放。The text reader has been disposed.

以前的读取操作当前正在使用读取器。The reader is currently in use by a previous read operation.

注解

在任务完成后指定的字符数count读取参数或到达文件末尾。The task completes after either the number of characters specified by the count parameter are read or the end of the file is reached.

TextReader 类是抽象类。The TextReader class is an abstract class. 因此,您实例化它在代码中。Therefore, you do not instantiate it in your code. 有关使用的示例ReadAsync方法,请参阅StreamReader.ReadAsync方法。For an example of using the ReadAsync method, see the StreamReader.ReadAsync method.

另请参阅

ReadAsync(Memory<Char>, CancellationToken) ReadAsync(Memory<Char>, CancellationToken)

public virtual System.Threading.Tasks.ValueTask<int> ReadAsync (Memory<char> buffer, System.Threading.CancellationToken cancellationToken = null);
abstract member ReadAsync : Memory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
override this.ReadAsync : Memory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>

参数

buffer
Memory<Char>

返回

适用于