MemoryStream.Seek(Int64, SeekOrigin) 方法

定義

將目前資料流中的位置設定為指定的數值。Sets the position within the current stream to the specified value.

public:
 override long Seek(long offset, System::IO::SeekOrigin loc);
public override long Seek (long offset, System.IO.SeekOrigin loc);
override this.Seek : int64 * System.IO.SeekOrigin -> int64
Public Overrides Function Seek (offset As Long, loc As SeekOrigin) As Long

參數

offset
Int64

資料流中的新位置。The new position within the stream. 這是相對於 loc 參數,並且可能是正數或負數。This is relative to the loc parameter, and can be positive or negative.

loc
SeekOrigin

SeekOrigin 型別的值,做為搜尋參考點。A value of type SeekOrigin, which acts as the seek reference point.

傳回

資料流中的新位置,是組合初始的參考點和位移計算出來的。The new position within the stream, calculated by combining the initial reference point and the offset.

例外狀況

在資料流開始之前嘗試搜尋。Seeking is attempted before the beginning of the stream.

offset 大於 MaxValueoffset is greater than MaxValue.

有無效的 SeekOriginThere is an invalid SeekOrigin.

-或--or- offset 造成了算術溢位。offset caused an arithmetic overflow.

目前的資料流執行個體已關閉。The current stream instance is closed.

範例

這個程式碼範例是針對MemoryStream類別提供之較大範例的一部分。This code example is part of a larger example provided for the MemoryStream class.

// Set the stream position to the beginning of the stream.
memStream->Seek( 0, SeekOrigin::Begin );
// Set the position to the beginning of the stream.
memStream.Seek(0, SeekOrigin.Begin);
' Set the stream position to the beginning of the stream.
memStream.Seek(0, SeekOrigin.Begin)

備註

這個方法覆寫 Stream.SeekThis method overrides Stream.Seek.

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

如果使用非零Seek位移進行初始化, MemoryStream請勿使用方法來判斷資料流程中的新位置。Do not use the Seek method to determine the new position in the stream if the MemoryStream was initialized with a non-zero offset. 如果您這樣做Seek ,將會傳回不正確的值。If you do, Seek will return an inaccurate value. 相反地,請Position使用屬性來取得資料流程的新位置。Instead, use the Position property to get the new position of the stream.

適用於

另請參閱