C# Compiler Error
CS0575 – Only class types can contain destructors
Reason for the Error
You will get this error in your C# code when you have used a destructor or finalizer for a struct.
For example, let’s compile the below C# program
using System; namespace DeveloperPublishConsole1 { public struct Employee { // This will result in the error CS0575 ~Employee() { } } internal class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
You will receive the error code CS0575 because you have a destructor specified for the struct Employee.
Error CS0575 Only class types can contain destructors DeveloperPublishConsole1 C:\Users\Senthil\source\repos\DeveloperPublishConsole1\DeveloperPublishConsole1\Program.cs 8 Active
Solution
C# doesn’t allow a finalizer for a structure.
You can fix this error in your C# program by removing the finalizer that is defined for the struct.