What is Destructor in C#?
What is Destructor in C#?
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Ashutosh Kumar Verma
16-Nov-2021Destructor in C#:
A destructor is special type of method of a class and it is used in a class to destroy the object that are not longer used in program it also destroy the instance of class. In C#, destructor is invoke automatically whenever the class instance become unreachable.
Property of a Destructor:
There are following some property of a destructor in C# are as,]
1- A destructor can always used in a class.
2- A destructor is represented with tiled(~) operator.
3- A destructor will not any parameter and can not used any access modifier with destructor.
4- Destructor is automatically invoked by garbage collector when the class object are no longer used in the program.
Syntax –
Example-
Output: