MemoryStream.Seek(Int64, SeekOrigin) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將目前資料流中的位置設定為指定的數值。
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
資料流中的新位置。 這是相對於 loc
參數,並且可能是正數或負數。
- loc
- SeekOrigin
SeekOrigin 類型的值,做為搜尋參考點。
傳回
資料流中的新位置,是組合初始的參考點和位移計算出來的。
例外狀況
在資料流開始之前嘗試搜尋。
offset
大於 Int32.MaxValue。
目前的資料流執行個體已關閉。
範例
此程式代碼範例是針對 類別提供的較大範例的 MemoryStream 一部分。
// 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.Seek。
支援搜尋超過數據流長度的任何位置。
請勿使用 Seek 方法,以 MemoryStream 非零位移初始化 時,判斷數據流中的新位置。 如果您這麼做, Seek 將會傳回不正確的值。 請改用 Position 屬性來取得數據流的新位置。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應