可能重复:
Close and Dispose - which to call?
你好,
在阅读了一些网页之后,我仍然不理解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
我创建的类?