Stream.Seek(0, SeekOrigin.Begin) or Position = 0

后端 未结 2 1328
庸人自扰
庸人自扰 2020-11-29 19:32

When you need to reset a stream to beginning (e.g. MemoryStream) is it best practice to use

stream.Seek(0, SeekOrigin.Begin);

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 20:20

    Use Position when setting an absolute position and Seek when setting a relative position. Both are provided for convenience so you can choose one that fits the style and readability of your code. Accessing Position requires the stream be seekable so they're safely interchangeable.

提交回复
热议问题