C# Error CS0239 – ‘member’ : cannot override inherited member ‘inherited member’ because it is sealed

C# Compiler Error

CS0239 – ‘member’ : cannot override inherited member ‘inherited member’ because it is sealed

Reason for the Error

You will receive this error in your C# program when you have one of the member override a sealed inherited member which is not allowed.

For example, try to compile the below code snippet.

namespace DeveloperPubNamespace
{
    abstract class BaseEmployee
    {
        public abstract void SetId();
    }
    class Employee : BaseEmployee
    {
        public sealed override void SetId()
        { 
        }
    }
    class ContractEmployee : Employee
    {
        public override void SetId()
        {
        }
    }
    class Program
    {
        public static void Main()
        {
        }
    }
}

This program will result with the C# error code CS0239 because the SetId() in the Employee class is marked as sealed and we are trying to override it inside the ContractEmployee class.

Error CS0239 ‘ContractEmployee.SetId()’: cannot override inherited member ‘Employee.SetId()’ because it is sealed DeveloperPublish C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 15 Active

C# Error CS0239 – 'member' : cannot override inherited member 'inherited member' because it is sealed

Solution

To fix the error code CS0239 in C#, you should not be overriding a sealed inherited member as this is not allowed.

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