C# Destructor

C# Destructors are the methods that are useful to destroy the instances that are no longer needed. Since the .Net framework’s garbage collector will implicitly invoke the destructor whenever needed, the programmer has no control over it.

A destructor in C# won’t have any return type and modifiers. It doesn’t accept any parameters and it invokes when the program exits.

Internally, when the destructor called, the Finalize method inside the object’s base class gets invoked. The syntax of the destructor in C# programming language is

Class Program
{
---
---
 ~Program()
  {
  // code
  }
}

Here, ~Program() is a destructor, which should be the same as the class name preceded by the tilde (~) symbol.