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.

傳回

已經讀取的字元數目。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.

發生 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.

傳回

已經讀取的字元數目。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.

備註

基礎文字讀取器的位置會依讀入 buffer的字元數來前移。The 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. 這是 Read的封鎖版本。This is a blocking version of Read.

另請參閱

適用於