ReSharper Tip of the Day: Put into ‘using’ construct.
There has been some debate if you need every IDisposable should be disposed. From the documentation IDisposable is used to clean up any unmanaged resource.
Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector.
OK. That’s fine. I totally agree with that until I see DataTable is derived from a class, MarshallByValueComponent, that implements IDisposable. Does that mean DataTable has unmanaged resources? Any way, on to the tip.
ReSharper notices when an object is created that implements IDisposable and it can automatically wrap the usage in a using block. Say you have the following code:

…and want to put it in a using block. Trusty ALT+Enter steps in a gives you the following options:

It is creates a nice using block around the object and all of its usages.

What would really be nice is we could create a warning when we see ourselves using an IDisposible without calling Dispose. That might be more difficult than finding one outside of a using. We could be calling Dispose in a try/finally or somewhere else.






