How to Dispose an object using Dispose method
This question already has an answer here:
The dispose method works together with the using
statement. It will automatically called if a using
block is closed.
class A : IDisposable
{
public void Dispose()
{
// Dispose
}
}
using (A a = new A())
{
}
You also don't need to override
the method, because it is defined in an interface.
In any case using
is leaved, dispose will be called.
下一篇: 如何使用Dispose方法处理对象