MemoryStream.Seek(Int64, SeekOrigin) 方法


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

 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



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


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.

如果 MemoryStream 是以非零位移進行初始化,請不要使用 Seek 方法來判斷資料流程中的新位置。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.