Stream.Seek(Int64, SeekOrigin) 方法

定義

在衍生類別中覆寫時,設定在目前資料流的位置。When overridden in a derived class, sets the position within the current stream.

public:
 abstract long Seek(long offset, System::IO::SeekOrigin origin);
public abstract long Seek (long offset, System.IO.SeekOrigin origin);
abstract member Seek : int64 * System.IO.SeekOrigin -> int64
Public MustOverride Function Seek (offset As Long, origin As SeekOrigin) As Long

參數

offset
Int64

相對於 origin 參數的位元組位移。A byte offset relative to the origin parameter.

origin
SeekOrigin

SeekOrigin 類型的值,表示用來取得新位置的參考點。A value of type SeekOrigin indicating the reference point used to obtain the new position.

傳回

目前資料流內的新位置。The new position within the current stream.

例外狀況

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

資料流不支援搜尋,例如資料流為管道或主控台 (Console) 輸出所建構。The stream does not support seeking, such as if the stream is constructed from a pipe or console output.

關閉資料流後呼叫了方法。Methods were called after the stream was closed.

備註

使用 CanSeek 屬性來判斷目前的實例是否支援搜尋。Use the CanSeek property to determine whether the current instance supports seeking.

如果 offset 為負數,則必須將新位置放在由 origin 所指定的位置前面,offset所指定的位元組數。If offset is negative, the new position is required to precede the position specified by origin by the number of bytes specified by offset. 如果 offset 為零(0),則新位置必須是 origin所指定的位置。If offset is zero (0), the new position is required to be the position specified by origin. 如果 offset 是正數,則需要新的位置,以遵循 offset所指定的位元組數目 origin 所指定的位置。If offset is positive, the new position is required to follow the position specified by origin by the number of bytes specified by offset.

從支援搜尋的 Stream 衍生的類別必須覆寫此方法,以提供上述功能。Classes derived from Stream that support seeking must override this method to provide the functionality described above.

支援搜尋超出資料流程長度的任何位置。Seeking to any location beyond the length of the stream is supported.

適用於

另請參閱