What is the advantage or disadvantage (or the difference) to use
memoryStream.Seek(0, SeekOrigin.Begin);
instead of
memoryStream.Position = 0
MemoryStream Seek Sets the position within the current stream to the specified value.
MemoryStream(Byte[]) Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array. MemoryStream(Byte[], Boolean) Initializes a new non-resizable instance of the MemoryStream class based on the specified byte array with the CanWrite property set as specified.
Sets the current position of this stream to the given value.
The only advantage of Position
is a shorter, more direct notation.
The advantage of Seek(0, SeekOrigin.Begin)
is that you also have SeekOrigin.Current
and SeekOrigin.End
.
But they are functionally the same, pick whatever you think is most readable.
They're both the same internally and set the position of the stream. See MSDN Stream.Seek.
Position
is absolute while Seek
provides a relative / offset position.
Whatever you prefer for readability.
Stream.Position += 50;
Stream.Seek(50, SeekOrigin.Current);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With