Stream.Seek(Int64, SeekOrigin) Stream.Seek(Int64, SeekOrigin) Stream.Seek(Int64, SeekOrigin) Stream.Seek(Int64, SeekOrigin) Method

定义

当在派生类中重写时,设置当前流中的位置。When overridden in a derived class, sets the position within the current stream.

public:
 abstract long Seek(long offset, System::IO::SeekOrigin origin);
public abstract long Seek (long offset, System.IO.SeekOrigin origin);
abstract member Seek : int64 * System.IO.SeekOrigin -> int64
Public MustOverride Function Seek (offset As Long, origin As SeekOrigin) As Long

参数

offset
Int64 Int64 Int64 Int64

相对于 origin 参数的字节偏移量。A byte offset relative to the origin parameter.

origin
SeekOrigin SeekOrigin SeekOrigin SeekOrigin

SeekOrigin 类型的值,指示用于获取新位置的参考点。A value of type SeekOrigin indicating the reference point used to obtain the new position.

返回

当前流中的新位置。The new position within the current stream.

异常

出现 I/O 错误。An I/O error occurs.

流不支持查找,例如在流通过管道或控制台输出构造的情况下即为如此。The stream does not support seeking, such as if the stream is constructed from a pipe or console output.

在流关闭后调用方法。Methods were called after the stream was closed.

注解

使用CanSeek属性来确定当前实例是否支持查找。Use the CanSeek property to determine whether the current instance supports seeking.

如果offset为负,则新位置需要前加上指定的位置origin按指定的字节数offsetIf offset is negative, the new position is required to precede the position specified by origin by the number of bytes specified by offset. 如果offset是零 (0),则新位置是需要将指定的位置originIf offset is zero (0), the new position is required to be the position specified by origin. 如果offset为正,则新位置是需要由指定的位置之后origin按指定的字节数offsetIf offset is positive, the new position is required to follow the position specified by origin by the number of bytes specified by offset.

类派生自Stream支持查找必须重写此方法以提供上文所述的功能。Classes derived from Stream that support seeking must override this method to provide the functionality described above.

支持查找到流的长度超出任何位置。Seeking to any location beyond the length of the stream is supported.

适用于

另请参阅