Why destructor is important to use | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Why destructor is important to use

what happened if we do not use it.

17th Apr 2017, 5:48 PM
minakshi singh
minakshi singh - avatar
4 Answers
+ 9
@Valdemar🙂
17th Apr 2017, 6:36 PM
minakshi singh
minakshi singh - avatar
+ 8
thanks@Ismail
17th Apr 2017, 6:14 PM
minakshi singh
minakshi singh - avatar
+ 4
To do some things you want before the destruction of the object like closing DB connection...
17th Apr 2017, 6:12 PM
Ismail
Ismail - avatar
+ 4
In practice destructors are rarely coded in C#. It is much more common to have your class implement IDisposable interface and use an using statement unless you have unmanaged resources. But you will probably learn about this in the future ☺️ But if anyone is interested and wants a bit more info then you can read the correct usage here: http://stackoverflow.com/a/898867
17th Apr 2017, 6:33 PM
Valdemar
Valdemar - avatar