How to make an IDisposable object a class variable?

Posted by Ben Aston on Stack Overflow See other posts from Stack Overflow or by Ben Aston
Published on 2010-03-14T00:44:00Z Indexed on 2010/03/14 0:45 UTC
Read the original article Hit count: 552

I am working with Active Directory using C#. Instantiating the PrincipalContext object seems to be expensive, so I'd like to store one in a class variable.

When using PrincipalContext as a local variable, I can use the convenient using syntax. When storing an IDisposable object in a static variable, how do I ensure the object is properly disposed of?

© Stack Overflow or respective owner

Related posts about idisposable

Related posts about class-variables