When you need to reset a stream to beginning (e.g. MemoryStream
) is it best practice to use
stream.Seek(0, SeekOrigin.Begin);
or
stream.Position = 0;
I've seen both work fine, but wondered if one was more correct than the other?
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.