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
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.
Answer checked How we write and check questions
Discussion