Stream.Seek(Int64, SeekOrigin) 方法

定义

当在派生类中重写时,设置当前流中的位置。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

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

origin
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为负,则需要在由指定的字节offset数之前origin指定的新位置。If 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),则新位置需要是origin指定的位置。If offset is zero (0), the new position is required to be the position specified by origin. 如果offset为正,则需要在由指定的字节offset数后跟随origin新位置。If 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.

适用于

另请参阅