.Net MemoryStream关闭问题
对于.Net MemoryStream对象实例,使用后是否需要显式关闭它?或者说不需要关闭?哪些是最佳实践?
我使用的是 VSTS2008 + .Net 3.5 + C#。
For a .Net MemoryStream object instance, do I need to close it explicitly after using it? Or no need to close it? Which is the best practices?
I am using VSTS2008 + .Net 3.5 + C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更好的是使用
Using
一点提醒 - 如果您打算最后将其全部写入另一个流中,请不要忘记
Flush()
(并且不要不要把马桶座圈打开)。我在毫秒左右使用 StreamWriter,将文本数据写入内存,最后将其全部写入光盘。 (如果您愿意,我也可以将此处的示例更改为这种情况)
Better yet would be to use
Using
A little reminder - if you plan to write it all into another stream at the end, don't forget to
Flush()
(And don't leave the toilet seat up).I use a StreamWriter around the ms, to write text data into the memory, and at the end put it all on disc in one go. (I can also change the example here to this case, if you'd like)
完成后应该将其关闭。最佳实践是在 try-catch-finally 块的 finally 部分关闭流。您可以在此处获取更多信息:
http://msdn.microsoft .com/en-us/library/system.io.memorystream.aspx
you should close it when you are done with it. The best practice is to close the stream in the finally section of a try-catch-finally block. you can get more information here:
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx