TextReader.Read TextReader.Read TextReader.Read TextReader.Read Method

定義

從文字讀取器讀取資料。Reads data from the text reader.

多載

Read() Read() Read() Read()

自文字讀取器讀取下一個字元,並將字元位置前移一個字元。Reads the next character from the text reader and advances the character position by one character.

Read(Span<Char>) Read(Span<Char>) Read(Span<Char>) Read(Span<Char>)
Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32)

從目前讀取器讀取指定的最大字元數目,並從指定的索引開始將資料寫入緩衝區。Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index.

Read() Read() Read() Read()

自文字讀取器讀取下一個字元,並將字元位置前移一個字元。Reads the next character from the text reader and advances the character position by one character.

public:
 virtual int Read();
public virtual int Read ();
abstract member Read : unit -> int
override this.Read : unit -> int
Public Overridable Function Read () As Integer

傳回

文字讀取器的下一個字元;如果不再有字元可供使用,則為 -1。The next character from the text reader, or -1 if no more characters are available. 預設的實作會傳回 -1。The default implementation returns -1.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

備註

TextReader 類別是抽象類別。The TextReader class is an abstract class. 因此,您的程式碼中不必將它執行個體化。Therefore, you do not instantiate it in your code. 如需使用的範例Read方法,請參閱StreamReader.Read方法。For an example of using the Read method, see the StreamReader.Read method.

另請參閱

Read(Span<Char>) Read(Span<Char>) Read(Span<Char>) Read(Span<Char>)

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

參數

buffer
Span<Char>

傳回

Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32) Read(Char[], Int32, Int32)

從目前讀取器讀取指定的最大字元數目,並從指定的索引開始將資料寫入緩衝區。Reads a specified maximum number of characters from the current reader and writes the data to a buffer, beginning at the specified index.

public:
 virtual int Read(cli::array <char> ^ buffer, int index, int count);
public virtual int Read (char[] buffer, int index, int count);
abstract member Read : char[] * int * int -> int
override this.Read : char[] * int * int -> int
Public Overridable Function Read (buffer As Char(), index As Integer, count As Integer) As 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 reader is reached before the specified number of characters is read into the buffer, the method returns.

傳回

已經讀取的字元數目。The number of characters that have been read. 數目將小於或等於 count,取決於資料是否在讀取器裡可供使用。The number will be less than or equal to count, depending on whether the data is available within the reader. 如果不再有字元可供讀取時呼叫,這個方法傳回 0 (零)。This method returns 0 (zero) if it is called when no more characters are left to read.

例外狀況

緩衝區長度減去 index 會小於 countThe buffer length minus index is less than count.

發生 I/O 錯誤。An I/O error occurs.

備註

這個方法傳回之後count會讀取的字元,或檔案結尾為止。This method returns after either count characters are read or the end of the file is reached. ReadBlock 是封鎖的版本,這個方法。is a blocking version of this method.

TextReader 類別是抽象類別。The TextReader class is an abstract class. 因此,您的程式碼中不必將它執行個體化。Therefore, you do not instantiate it in your code. 如需使用的範例Read方法,請參閱StreamReader.Read方法。For an example of using the Read method, see the StreamReader.Read method.

另請參閱

適用於