Stream.Seek(Int64, SeekOrigin) Stream.Seek(Int64, SeekOrigin) Stream.Seek(Int64, SeekOrigin) Stream.Seek(Int64, SeekOrigin) Method

定義

在衍生類別中覆寫時,設定在目前資料流的位置。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 Int64 Int64 Int64

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

origin
SeekOrigin SeekOrigin SeekOrigin 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所指定的位元組數offsetIf 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)、 新的位置是一定要指定的位置originIf offset is zero (0), the new position is required to be the position specified by origin. 如果offset為正數,則新的位置,才能遵循所指定的位置origin所指定的位元組數offsetIf 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.

適用於

另請參閱