Interview Question

What is IDisposable?

IDisposable supports deterministic cleanup, normally through using.

💡 Concept ✅ Quick Revision 🔷 C#

Answer

IDisposable defines deterministic cleanup through its Dispose method. • It is used for resources such as streams, handles, and database connections. • A using statement or declaration calls Dispose when scope exits. • Garbage collection manages memory but does not replace timely cleanup of external resources.

💡 C# Example

using var stream = File.OpenRead("data.bin"); Console.WriteLine(stream.Length);

Output

File length

⚡ Quick Revision

IDisposable supports deterministic cleanup, normally through using.