问题描述
的.NET MemoryStream的不出现具有.reset段或.Clear方法
The .NET MemoryStream does not appear to have a .Reset or .Clear method.
我在考虑使用以下code做到这一点的:
I was thinking of using the following code to accomplish this:
ms.Seek(0, IO.SeekOrigin.Begin)
ms.SetLength(0)
什么是正确的方式来清除或重置现有的.NET的MemoryStream?
What is the proper way to clear or reset an existing .NET MemoryStream?
推荐答案
将MemoryStream没有复位/清除方法,因为它是多余的。如果设置为长度为零你清除它。
The memorystream does not have a reset/clear method because it would be redundant. By setting it to zero length you clear it.
当然,你总是可以做:
memoryStream = new MemoryStream(memoryStream.Capacity());
此将产生你被初始化相同大小的一个MemoryStream
This would yield you a memorystream of the same size that is initialized.
如果你真的想手动清除该流我怀疑你将不得不求助于通过元素循环。
If you really want to manually clear the stream I suspect you would have to resort to looping through the elements.
这篇关于复位或清除.NET的MemoryStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!