You can't have one without the other.
When you write :
using(MyClass myObj = new MyClass())
{
myObj.SomeMthod(...);
}
Compiler will generate something like this :
MyClass myObj = null;
try
{
myObj = new MyClass();
myObj.SomeMthod(...);
}
finally
{
if(myObj != null)
{
((IDisposable)myObj).Dispose();
}
}
So as you can see while having using
keyword it is assumed/required that IDisposable is implemented.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…