Practice mode C#

What is the purpose of implementing IDisposable in a C# class?

Correct answer B. To give callers a Dispose method that releases unmanaged or expensive resources deterministically

Explanation

The garbage collector frees managed memory but not unmanaged resources such as file handles, database connections or native memory, and it runs at unpredictable times. IDisposable defines a single Dispose method for releasing those resources as soon as the caller is finished, typically through a using statement. It does not affect serialisation or prevent collection.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.