System.IO.MemoryStream.Seek Method

Sets the position within the current stream to the specified value.

Syntax

public override long Seek (long offset, SeekOrigin loc)

Parameters

offset
The new position within the stream. This is relative to the loc parameter, and can be positive or negative.
loc
A value of type System.IO.SeekOrigin, which acts as the seek reference point.

Returns

The new position within the stream, calculated by combining the initial reference point and the offset.

Exceptions

TypeReason
System.IO.IOExceptionSeeking is attempted before the beginning of the stream.
ArgumentOutOfRangeException offset is greater than the maximum length of System.IO.MemoryStream.
ArgumentException loc is not a valid System.IO.SeekOrigin value.
ObjectDisposedException The current stream is closed.

Remarks

This method overrides Stream.Seek(long, SeekOrigin).

Seeking to any location beyond the length of the stream is supported.

Do not use the MemoryStream.Seek(long, SeekOrigin) method to determine the new position in the stream if the System.IO.MemoryStream was initialized with a non-zero offset. If you do, MemoryStream.Seek(long, SeekOrigin) will return an inaccurate value. Instead, use the MemoryStream.Position property to get the new position of the stream.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0