读完线程Is SqlCommand.Dispose enough?和Closing and Disposing a WCF Service之后,我想知道对于SqlConnection这样的类,或者从Stream类继承的几个类中的一个类,关闭Dispose而不是关闭有关系吗?
读完线程Is SqlCommand.Dispose enough?和Closing and Disposing a WCF Service之后,我想知道对于SqlConnection这样的类,或者从Stream类继承的几个类中的一个类,关闭Dispose而不是关闭有关系吗?
According to Microsoft guidelines, it's a good practice to provide Close
method where suitable. Here is a citation from Framework design guidelines
除了
Dispose()
之外,考虑提供方法Close()
,如果在该区域中关闭是标准术语.进行此操作时,让Close
实现与Dispose
相同非常重要...
在大多数情况下,Close
和Dispose
方法是等效的.在SqlConnectionObject
的情况下,Close
和Dispose
之间的main difference是:
一个应用程序可以调用
Close
多个 不止一次.也不例外 已生成.如果你调用
Dispose
方法
也就是说: