I’m coding in C# and I created a class that I would like to use in a ‘using’ block.
Is this possible and if so, how should I proceed and what to I need to add to my class?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
usingkeyword can be used on any object that implementsIDisposable. To implementIDisposable, include aDisposemethod in your class.It’s usually important to also include the
Disposefunctionality in your class’s finalizer in case users of your library don’t (or forget to) callDispose.For example: