c# - 什么时候应该在C#中使用using(…){…}?

标签 c#

I see it used and I read about it here and there and it has something to do with memory management. Question is, how do you know when you should use it? How do you tell the difference between variables or instances that will cause a problem if you don't use it?

Exact duplicate: What is the C# Using block and why should I use it?

最佳答案

每当实例化实现IDisposable的类的对象时。

关于c# - 什么时候应该在C#中使用using(…){…}? ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/678781/

相关文章:

c# - 为什么在不修改枚举集合时得到 "Collection was modified; enumeration operation may not execute"?

c# - 接口(interface)依赖层次结构

c# - 使用静态 Func<> 投影单个记录

c# - 从泛型类中的接口(interface)继承

c# - 对列表进行排序,其中每个项目都指的是应该出现在它之前/之后的项目

c# - 如果子节点满足特定条件,则检索 XML 父节点属性并将两者分配给变量

c# - 从 C# 启动 Java 平台

c# - 如何从 RichTextBox 中的光标位置选择前一个字符

c# - 为什么字符串可以为空?

c# - Silverlight 中附加和非附加依赖属性之间的区别