inheritance - C#:What should be the content of the Dispose method when implementing IDisposable interface -


i created class implements idisposable interface , visualstudio ide brought dispose method me. wondering code should write inside dispose method take care of memory management or whatever stuff should do.

public class esnverification : idisposable  {     public bool save(string a,string b)   {     //save data table     return true;   }    public void dispose()   {        throw new notimplementedexception();        // should here  ?   } } 

i recommend three simple rules how implement idisposable; simplified here:

  • rule 1: don't (unless need to). there 2 situations when idisposable need implemented: the class owns unmanaged resource or the class owns managed (idisposable) resources.
  • rule 2: class owning managed resources, implement idisposable (but not finalizer). implementation of idisposable should call dispose each owned resource. class should not have finalizer.
  • rule 3: class owning single unmanaged resource, implement both idisposable , finalizer.

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -