Search code examples
c#using-statement

MCQ on using Statement for C# certification practice


Here's a question from the book: Programming in C#, Exam 70-483 The answer is c.

An object that is implementing IDisposable is passed to your class as an argument. Should you wrap the element in a using statement?

A. Yes, otherwise a memory leak could happen.
B. No, you should call Close on the object.
C. No, you should use a try/finally statement and call Dispose yourself.
D. No, the calling method should use a using statement.

I am a little confused why c. In the question, by argument, do they mean that the object is passed as a type arguement to the class?


Solution

  • Regardless of how or why or when the argument is passed, you should never destroy an instance which you did not create. (d) is correct, (c) is irrelevant.