C# Error CS0249 – Do not override object.Finalize. Instead, provide a destructor

C# Compiler Error

CS0249 – Do not override object.Finalize. Instead, provide a destructor.

Reason for the Error

You’ll receive this error in your C# program when you are trying to override the Finalize method that is defined in the System.Object class.

For example, lets try to compile the below code snippet.

namespace DeveloperPubNamespace
{
   class Program
    {
        public class Employee
        {
            protected override void Finalize() 
            {

            }
        }
        public static void Main()
        {
        }
    }
}

You will receive the error code CS0249 in your C# program because we are trying to override the Finalize() method in the Employee class.

Error CS0249 Do not override object.Finalize. Instead, provide a destructor. DeveloperPublish C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 7 Active

C# Error CS0249 – Do not override object.Finalize. Instead, provide a destructor

Solution

To fix the error code CS0249 in your C# program, replace the Finalize override method with the destructor method as shown below.

namespace DeveloperPubNamespace
{
   class Program
    {
        public class Employee
        {
            ~ Employee() 
            {

            }
        }
        public static void Main()
        {

        }
    }
}

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...