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

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

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