03-28-2015, 05:26 PM
I wouldn't call reader.close() in a using statement simply because that's not necessary.
The using directive calls Dispose() after executing and that takes care of closing the reader.
Side note:
If you want to implement it in your own classes e.g if your objects use unmanaged resources such as file handles:
That means every object x in the using statement [using (foo x = new foo())] has to implement the IDisposable interface inorder to use the using statement.
You can use multiple using statements at once.
You can't access the object outside the using statement.
Usualy the Dispose method is implemented as that:
public class Foo : IDisposable
{
private bool disposed = false;
/*
Implementation of your class
onmitted
*/
public void Dispose() {
Dispose(true);
GC.SupressFinialize(this);
}
protected virtual void Dispose(bool disposeManaged) {
if(disposed){
return;
}
if(disposeManaged){
//take care of managed objects here
}
//take care of unmanaged object here
disposed = true;
}
}

