The requested page is not available for the requested platform. You are viewing the content for Default platform.

Virtual member cannot be declared in sealed class

CodeRush Classic shows the Virtual member cannot be declared in sealed class code issue if a sealed class contains a virtual member declaration.

Fix

Make the member non-virtual.

Purpose

Highlights the virtual member declarations, which would cause the 'Member name' is a new virtual member in a sealed class compilation error.

Example

public sealed class MyClass
{
    public virtual void ProcessData(object data)
    {
        if (Data != null)
            Data = data;
    }
    public object Data { get; private set; }
}

Fix:

public sealed class MyClass
{
    public void ProcessData(object data)
    {
        if (Data != null)
            Data = data;
    }
    public object Data { get; private set; }
}