Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of implementing the IDisposable interface?

Tags:

c#

idisposable

What's the purpose of implementing the IDisposable interface? I've seen some classes implementing it and I don't understand why.

like image 390
MrDatabase Avatar asked Dec 01 '22 12:12

MrDatabase


1 Answers

If your class creates unmanaged resources, then you can implement IDisposable so that these resources will be cleaned up properly when the object is disposed of. You override Dispose and release them there.

like image 53
Ed S. Avatar answered Dec 10 '22 04:12

Ed S.