【发布时间】:2011-03-14 02:39:59
【问题描述】:
嗨,
看了一些网页,还是不明白C#中Dispose和Close方法的区别。
我们来取样:
using (SqlConnection sqlConnection = new SqlConnection())
{
// Execute an insert statement (no breaks, exceptions, returns, etc.)
}
还有第二个:
SqlConnection sqlConnection = new SqlConnection();
// Execute an insert statement (no breaks, exceptions, returns, etc.)
sqlConnection.Close();
这两段代码相似吗?两者都只是为了方便而提供(因为在某些情况下using 不是解决方案?或者行为有所不同?
那么为什么有些类提供Close 方法,我什么时候应该在我创建的IDisposable 类中放置Close 方法?
【问题讨论】:
-
感谢您注意它是重复的。我发帖前搜索了一下,没有找到。我要结束这个问题了。
标签: c# dispose idisposable