Skip to main content

Cannot override inherited sealed member

In This Article

CodeRush Classic shows the Cannot override inherited sealed member code issue if a member overrides the sealed member of the base class.

#Fix

Remove the sealed keyword from the overridden member declaration.

#Purpose

Highlights the member declaration statements, which would cause the Cannot override inherited member because it is sealed compilation error.

#Example

public abstract class TopClass
{
    public abstract void OutputText(string text);
}
public class BaseClass: TopClass
{
    public sealed override void OutputText(string text)
    {
        MessageBox.Show(text);
    }
}
public class MyClass: BaseClass
{
    public override void OutputText(string text)
    {
        Console.Write(text);
    }
}

Fix:

public abstract class TopClass
{
    public abstract void OutputText(string text);
}
public class BaseClass: TopClass
{
    public override void OutputText(string text)
    {
        MessageBox.Show(text);
    }
}
public class MyClass: BaseClass
{
    public override void OutputText(string text)
    {
        Console.Write(text);
    }
}