Destructors
Can anyone please tell me when/ why to use "Destructors" in C#? Pls give an easy example.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jan 20, 2012, 10:21 AM
Destructors are used to destruct instances of classes.
When we are using destructors in C#, we have to keep in mind the following things:
A class can only have one destructor.
Destructors cannot be inherited or overloaded.
Destructors cannot be called. They are invoked automatically.
A destructor does not take modifiers or have parameters.
A destructor same name as the name of the class but it starts with the character ~
Sam HobbsPosted Jan 20, 2012, 3:43 PM
I think the first thing that should be said about Destructors is that they are usually not needed. The most common use of destructors is to do cleanup of unmanaged objects. Managed objects in objects (classes and structs) that we define will do whatever cleanup that they need to do themselves and we do not need to do anything explicitly for the managed objects we use.
VulpesPosted Jan 20, 2012, 10:34 AM
http://msdn.microsoft.com/en-us/library/b1yfkh5e.aspx
Rashed MohammadPosted Jan 20, 2012, 10:15 AM
Posted Jan 20, 2012, 9:56 AM