Stream.ReadAtLeast(Span<Byte>, Int32, Boolean) 方法

定義

從目前的資料流程讀取至少一個位元組數目,並依讀取的位元組數目將資料流程中的位置往前移。

public int ReadAtLeast (Span<byte> buffer, int minimumBytes, bool throwOnEndOfStream = true);
member this.ReadAtLeast : Span<byte> * int * bool -> int
Public Function ReadAtLeast (buffer As Span(Of Byte), minimumBytes As Integer, Optional throwOnEndOfStream As Boolean = true) As Integer

參數

buffer
Span<Byte>

記憶體區域。 當這個方法傳回時,這個區域的內容會由從目前資料流程讀取的位元組取代。

minimumBytes
Int32

要讀取至緩衝區的位元組數目下限。

throwOnEndOfStream
Boolean

true 表示如果在讀取 minimumBytes 位元組之前到達資料流程結尾,則會擲回例外狀況; false 傳回小於 minimumBytes 到達資料流程結尾的時間。 預設值為 true

傳回

緩衝區所讀取的總位元組數。 當 為 truethrowOnEndOfStream ,這保證大於或等於 minimumBytes 。 達到資料流程結尾且 throwOnEndOfStreamfalse 時,這會小於 minimumBytes 。 如果目前無法使用許多位元組,這可以小於緩衝區中配置的位元組數目。

例外狀況

minimumBytes 為負數,或大於 的 buffer 長度。

throwOnEndOfStreamtrue ,而且在讀取 minimumBytes 資料的位元組之前,會到達資料流程的結尾。

備註

minimumBytes 為 0 (零) 時,此讀取作業將會完成,而不會等待資料流程中的可用資料。

適用於