StringReader.ReadBlockAsync 方法

定義

多載

名稱 Description
ReadBlockAsync(Memory<Char>, CancellationToken)

非同步讀取輸入字串中從當前位置開始的所有字元,並將當前位置推進到輸入字串的末尾。

ReadBlockAsync(Char[], Int32, Int32)

非同步讀取目前字串指定的最大字元數,並將資料寫入緩衝區,從指定的索引開始。

ReadBlockAsync(Memory<Char>, CancellationToken)

非同步讀取輸入字串中從當前位置開始的所有字元,並將當前位置推進到輸入字串的末尾。

public override System.Threading.Tasks.ValueTask<int> ReadBlockAsync(Memory<char> buffer, System.Threading.CancellationToken cancellationToken = default);
override this.ReadBlockAsync : Memory<char> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<int>
Public Overrides Function ReadBlockAsync (buffer As Memory(Of Char), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of Integer)

參數

buffer
Memory<Char>

當此方法回傳時,包含從當前來源讀取的字元。 若讀取字元總數為零,則該區間保持不變。

cancellationToken
CancellationToken

用來監控取消申請的代幣。 預設值為 None

傳回

一個代表非同步讀取操作的任務。 參數的 TResult 值包含讀取到緩衝區的總字元數。

例外狀況

取消令牌也被取消了。 此例外會儲存在回傳的任務中。

備註

ReadBlockAsync(Memory<Char>, CancellationToken) 非同步呼叫 ReadBlock(Span<Char>) ,而非同步呼叫則直接呼叫 Read(Span<Char>)

適用於

ReadBlockAsync(Char[], Int32, Int32)

非同步讀取目前字串指定的最大字元數,並將資料寫入緩衝區,從指定的索引開始。

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

參數

buffer
Char[]

當此方法回傳時,包含指定的字元陣列,且介於 index 和 之間的index + count 值( - 1)被從當前來源讀取的字元取代。

index
Int32

開始寫作的姿勢 buffer

count
Int32

最多可閱讀字元數。 若字串末尾在緩衝區寫入指定字元數前到達,方法會回傳。

傳回

一個代表非同步讀取操作的任務。 參數的 TResult 值包含讀取到緩衝區的總位元組數。 若目前可用位元組數少於請求的位元組數,結果值可小於請求的位元組數;若字串末尾已達,則可為 0(零)。

屬性

例外狀況

buffernull

indexcount 是陰性。

index的和count大於緩衝區長度。

字串讀取器已被處理。

讀取器目前正被先前的讀取操作使用。

備註

任務直到讀取參數指定的 count 字元數或字串結束後才會完成。

適用於