I’ve been writing a lot of .NET code at work that has to Open() and Close() objects, and these objects typically provide a Dispose() method to release resources. As you know, wrapping something in a using() statement will craft a try/finally behind the scenes such that Dispose() will always get called. I had been told in years past that it’s necessary to call both Close() and Dispose() when finished with one of these objects, but didn’t understand why.
using(var foo = new ConnectionObject())
{
foo.Bar();
foo.Close(); //leave it out?
} //using block calls Dispose()
I told myself that I’d research it at some point in the future, and I finally found some time today.
In nearly every case, calling Close() and Dispose() will produce equivalent behavior. So why call just one or both? Typically calling Close() will close a connection and stop there, while Dispose() will both close the connection and reset the state of the connection (as well as releasing all resources). For this reason, you can call both because calling Close() twice is harmless (whereas calling Dispose() twice will blow up in your face).
So the moral of the story is to call Close() when you intend to reuse the same object state, and call Dispose() when you intend to be finished with it altogether.