I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... SQLConnection
, MemoryStream
, etc.
A quick&dirty way of checking if a type implements IDisposable is to create an instance of it and check if the instance has a Dispose() member function. If it does then you can be 99% sure that it implements IDisposable.
An simple way to get a list of types that implement IDisposable is to crack open Reflector, navigate to System.IDisposable
, expand the node, and then expand the 'Derived Types' node.
To be sure that your list is complete, verify that all the assemblies you're using have been 'Open'ed in Reflector.
In addition to the other answers, note that a class might implement IDisposable but not have Dispose come up in the intellisense list.
class MyClass :IDisposable
{
void IDisposable.Dispose()
{
/* Stuff */
}
}