次の方法で共有


MemoryStream.Seek メソッド

現在のストリーム内の位置を指定した値に設定します。

Overrides Public Function Seek( _
   ByVal offset As Long, _   ByVal loc As SeekOrigin _) As Long
[C#]
public override long Seek(longoffset,SeekOriginloc);
[C++]
public: __int64 Seek(__int64offset,SeekOriginloc);
[JScript]
public override function Seek(
   offset : long,loc : SeekOrigin) : long;

パラメータ

  • offset
    ストリームの新しい位置。これは loc パラメータに対する相対値であり、正または負の値にすることができます。
  • loc
    シーク参照ポイントとして機能する SeekOrigin 型の値。

戻り値

初期参照ポイントとオフセットを組み合わせて計算するストリーム内の新しい位置。

例外

例外の種類 条件
IOException ストリームの先頭より前をシークしようとしました。
ArgumentOutOfRangeException offsetMaxValue より大きな値です。
ArgumentException 無効な SeekOrigin があります。
ObjectDisposedException 現在のストリーム インスタンスが閉じています。

解説

ファイルの作成およびテキストのファイルへの書き込みの例については、「 ファイルへのテキストの書き込み 」を参照してください。ファイルからのテキストの読み取りの例については、「 ファイルからのテキストの読み取り 」を参照してください。バイナリ ファイルからの読み取りおよびバイナリ ファイルへの書き込みの例については、「 新しく作成したデータ ファイルの読み取りと書き込み 」を参照してください。

このメソッドは、 Seek をオーバーライドします。

ストリーム長を超えた位置へのシークがサポートされています。

使用例

[Visual Basic, C#, C++] 次のコード例は MemoryStream クラスの例の一部です。

 
' Set the stream position to the beginning of the stream.
memStream.Seek(0, SeekOrigin.Begin)

[C#] 
// Set the position to the beginning of the stream.
memStream.Seek(0, SeekOrigin.Begin);

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

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

MemoryStream クラス | MemoryStream メンバ | System.IO 名前空間 | 入出力操作 | ファイルからのテキストの読み取り | ファイルへのテキストの書き込み