If I am using the using keyword, do I still have to implement IDisposable?
If I am using the using keyword, do I still have to implement IDisposable
Share
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.
If you use the
usingstatement the enclosed type must already implementIDisposableotherwise the compiler will issue an error. So consider IDisposable implementation to be a prerequisite of using.If you want to use the
usingstatement on your custom class, then you must implementIDisposablefor it. However this is kind of backward to do because there’s no sense to do so for the sake of it. Only if you have something to dispose of like an unmanaged resource should you implement it.This enables you to:
Effectively that’s the same as writing: