C# Destructors

A Destructor destructs an object. It has the same name as the class name and gets automatically called when an object gets created like Constructors.

Syntax – Destructors

Let us see the syntax of Destructors with our class name Studyopedia. It is prefixed by a tilde sign as shown below:

As shown above, the Destructor syntax is like the Constructor, except for the prefixed tilde sign. Remember, the following points about Destructors:

  • Define Destructor only once in a class
  • Destructors cannot return a value
  • Destructors cannot have parameters like Constructors.
  • The Destructors cannot be overloaded.
  • The Destructors cannot be inherited.

Example – Destructors

Let us now see an example of Destructors in C++:


C# Introduction
C# Constructors
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading