StringReader.Peek 方法

定義

傳回下一個可供使用的字元,但不使用它。Returns the next available character but does not consume it.

public:
 override int Peek();
public override int Peek ();
override this.Peek : unit -> int
Public Overrides Function Peek () As Integer

傳回

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

例外狀況

目前的讀取器已關閉。The current reader is closed.

備註

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.Peek 方法。This method overrides the TextReader.Peek method.

這項作業不會變更 StringReader 的目前位置。The current position of the StringReader is not changed by this operation.

下表列出其他一般或相關 i/o 工作的範例。The following table lists examples of other typical or related I/O tasks.

若要執行相關作業…To do this... 請參閱這個主題中的範例…See the example in this topic...
建立文字檔Create a text file. 如何:將文字寫入檔案How to: Write Text to a File
寫入文字檔。Write to a text file. 如何:將文字寫入檔案How to: Write Text to a File
從文字檔讀取。Read from a text file. 如何:從檔案讀取文字How to: Read Text from a File
取得檔案的大小。Get the size of a file. FileInfo.Length

適用於

另請參閱