TextReader.Peek TextReader.Peek TextReader.Peek TextReader.Peek Method


讀取下一個字元,而不會變更讀取器或字元來源的狀態。Reads the next character without changing the state of the reader or the character source. 傳回下一個可用字元,而不會實際從讀取器讀取。Returns the next available character without actually reading it from the reader.

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


整數,表示要讀取的下一個字元,如果沒有更多字元可供使用或讀取器不支援搜尋,則為 -1。An integer representing the next character to be read, or -1 if no more characters are available or the reader does not support seeking.


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


Peek方法會傳回整數值,以判斷是否發生檔案或另一個錯誤的結尾。The Peek method returns an integer value in order to determine whether the end of the file, or another error has occurred. 這可讓使用者能夠先檢查 是否傳回的值為-1 的之前先將它轉換Char型別。This allows a user to first check if the returned value is -1 before casting it to a Char type.

目前的位置TextReader這項作業不會變更。The current position of the TextReader is not changed by this operation. 傳回的值為-1,如果沒有更多字元可供使用。The returned value is -1 if no more characters are available. 預設的實作會傳回 -1。The default implementation returns -1.

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