---
title: "What is Destructor in C#?"  
description: "What is Destructor in C#?"  
author: "Steilla Mitchel"  
published: 2021-11-15  
updated: 2021-11-15  
canonical: https://www.mindstick.com/forum/156838/what-is-destructor-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# What is Destructor in C#?

What is [Destructor in C#](https://answers.mindstick.com/qa/82398/what-is-destructor-in-c-sharp)?

## Replies

### Reply by Ashutosh Kumar Verma

## Destructor 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 –

```
Class Demo
{
~Demo()
{	// code of destructor
}
}
```

## Example-

```
using System;
namespace MindStick
{
    class Demo
    {
       public Demo()
       {
           Console.WriteLine('An Instance is Created');
       }
       // Destructor
       ~Demo()
       {
          Console.WriteLine('An Instance is destroyed');
       }
    }
    class SampleProgram
    {
       static void Main(string[] args)
       {
          Details();
          GC.Collect();
          Console.ReadLine();
       }
       public static void Details()
       {
          // Created instance of the class
          Demo user = new Demo();
       }
    }
}
```

## Output:

```
An Instance is Created
An Instance is destroyed
```

\


---

Original Source: https://www.mindstick.com/forum/156838/what-is-destructor-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
