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

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...