Skip to main content

Cannot inherit from sealed type

In This Article

CodeRush Classic shows the Cannot inherit from sealed type code issue if a class inherits from a sealed type.

#Fix

Remove the sealed keyword from the base class declaration or make the current class not a descendant of the sealed class.

#Purpose

Highlights the class declaration statements, which would cause the Cannot derive from sealed type compilation error.

#Example

sealed class MyClass
{
    public void OutputText(string text)
    {
        Console.Write(text);
    }
}
class TestClass: MyClass
{

}

Fixes:

class MyClass
{
    public void OutputText(string text)
    {
        Console.Write(text);
    }
}
class TestClass: MyClass
{

}
sealed class MyClass
{
    public void OutputText(string text)
    {
        Console.Write(text);
    }
}
class TestClass
{
    public void OutputText(string text)
    {
        Console.Write(text);
    }
}