C# Error CS0574 – Name of destructor must match name of class

C# Compiler Error

CS0574 – Name of destructor must match name of class

Reason for the Error

You will get this error in your C# code when the name of the destructor or finalizer is different from the class name followed by the tilde symbol.

For example, let’s compile the below C# program

using System;

namespace DeveloperPublishConsoleCore
{
    public class Employee
    {
        ~ Employee1()
        {

        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("DeveloperPublish Hello World!");
        }
    }
}

You will receive the error code CS0574 because you have a destructor with the name Employee1 which is different from the class name “Employee”.

Error CS0574 Name of destructor must match name of type DeveloperPublishConsoleCore C:\Users\senth\source\repos\DeveloperPublishConsoleCore\DeveloperPublishConsoleCore\Program.cs 7 Active

C# Error CS0574 – Name of destructor must match name of class

Solution

You can fix this error in your C# program by ensuring that the name of the destructor matches with the name of the class.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...