How to implement IDisposable properly

Posted by Vince on Stack Overflow See other posts from Stack Overflow or by Vince
Published on 2010-04-29T10:10:48Z Indexed on 2010/04/29 10:17 UTC
Read the original article Hit count: 205

Filed under:
|

Hi,

I've seen so much C# code in my time as a developer that attempt to help the GC along by setting variables to null or calling Dispose() on classes (DataSet for example) within thier own classes Dispose() method that I've been wondering if there's any need to implement it in a managed environment.

Is this code a waste of time in its design pattern?

class MyClass : IDisposable {

        #region IDisposable Members

        public void Dispose() {
otherVariable = null;
            if (dataSet != null)
                dataSet.Dispose();


        }

        #endregion
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about idisposable