Skip to main content

Member cannot be sealed because it is not an override

In This Article

CodeRush Classic shows the Member cannot be sealed because it is not an override code issue if a non-override member is marked sealed.

#Fix

Add the override keyword to the sealed member declaration.

#Purpose

Highlights the sealed member declarations, which would cause the “‘Member name’ cannot be sealed because it is not an override” compilation error.

#Example

public class MyBase
{
    public virtual void OutputText(string text)
    {
        Console.WriteLine(text);
    }
}
public class MyClass: MyBase
{
    private List<string> _ShownStrings;
    public sealed void OutputText(string text)
    {
        if (_ShownStrings == null)
            _ShownStrings = new List<string>();
        base.OutputText(text);
        _ShownStrings.Add(text);
    }
}

Fix:

public class MyBase
{
    public virtual void OutputText(string text)
    {
        Console.WriteLine(text);
    }
}
public class MyClass: MyBase
{
    private List<string> _ShownStrings;
    public sealed override void OutputText(string text)
    {
        if (_ShownStrings == null)
            _ShownStrings = new List<string>();
        base.OutputText(text);
        _ShownStrings.Add(text);
    }
}