Reset or Clear .NET MemoryStream

user113476 picture user113476 · Mar 17, 2010 · Viewed 63.4k times · Source

The .NET MemoryStream does not appear to have a .Reset or .Clear method.

I was thinking of using the following code to accomplish this:

ms.Seek(0, IO.SeekOrigin.Begin)
ms.SetLength(0)

What is the proper way to clear or reset an existing .NET MemoryStream?

Answer

Andrew Bezzub picture Andrew Bezzub · Mar 17, 2010

Why do you need resetting memory stream? You always can create a new one. Or you can use:

memoryStream.SetLength(0);