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.

SeekOrigin 无效。There 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.

适用于

另请参阅