Advantage / Disadvantage of MemoryStream.Position or MemoryStream.Seek

What is the advantage or disadvantage (or difference) in use

memoryStream.Seek(0, SeekOrigin.Begin);

instead

memoryStream.Position = 0

+6
source share
3 answers

The only advantage of Position is a shorter, more direct designation.

The advantage of Seek(0, SeekOrigin.Begin) is that you also have SeekOrigin.Current and SeekOrigin.End .

But they are functionally the same, choose what you think is the most readable.

+9
source

They are the same inside and set the position of the flow. See MSDN Stream.Seek . Position is absolute, and Seek is relative / offset position.

No matter what you prefer for readability.

 Stream.Position += 50; Stream.Seek(50, SeekOrigin.Current); 
+1
source

Already answered here: Stream.Seek (0, SeekOrigin.Begin) or Position = 0

And I agree with pride. However, I see no real reason to use the Seek method in your scenario.

+1
source

Source: https://habr.com/ru/post/911568/


All Articles