"IDisposable Interface" article tells: 为什么?为什么只不受管理?在我的一生中,我认为它的主要用途是释放任何资源:托管(与数据库的连接,服务代理等)和非托管(如果在应用程序中使用了这些资源).Whole my life I thought its PRIMIRALY use is to release ANY resources: managed (connections to DBs, services proxies, etc) and unmanaged (if they are used in application). P.S.我相信有关此主题的问题已经存在,但找不到.I believe there are already questions on this topic, but can't find them.推荐答案与db的基础连接,文件句柄和许多其他低级别的o/s对象也不受管理.他们不受管.实现IDisposable接口意味着您不仅仅依赖于垃圾回收器来释放这些资源;它还可以用来创建资源.但是您将使用可用的低级API关闭这些资源.The underlying connections to db's are not managed, as are file handles and a number of other low-level o/s objects. They are unmanaged. Implementing an IDisposable interface implies that you are not just relying on the garbage collector to release those resources; but you are closing those resources using what ever low-level API that you have available.此外,我认为Eric Lippert的答案(第二倒),很好地解释了为什么要使用IDisposable.Also, I think Eric Lippert's answer (2nd one down) to a similar question is a very good explanation on why you would use IDisposable. 这篇关于IDisposable接口的主要用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 05:57