Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • pretty much memory critical, but perfectly suits my needs for small streams. ;) Commented Mar 18, 2016 at 14:27
  • 1
    Why do you set Position = 0? MemoryStream.ToArray() documentation says "Writes the stream contents to a byte array, regardless of the Position property." Commented Mar 2, 2017 at 2:55
  • 1
    Just habit I suppose, from being bit by bit setting the position before operating on the stream. Commented Mar 2, 2017 at 12:05
  • 1
    This is a poor solution, quite aside from the fact that it requires allocating as much memory as the entire length of file (times two). If you have two big files and they differ at the start of the stream, this will wait until the entire contents of both files have been read to detect that and abort. Commented Jun 11, 2019 at 22:04
  • 1
    @MahmoudAl-Qudsi the request was to compare two memory streams, which by definition, are already in memory, not files. Commented Jun 12, 2019 at 18:20