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

Virtual member cannot be declared in structures

CodeRush Classic shows the Virtual member cannot be declared in structures code issue if a virtual member is declared in a structure.

Fix

Make the member non-virtual.

Purpose

Highlights the virtual member declarations, which would cause the The modifier 'virtual' is not valid for this item compilation error.

Example

public struct MyStruct
{
    public virtual void ProcessData(object data)
    {
        if (Data != null)
            Data = data;
    }
    public object Data { get; private set; }
}

Fix:

public struct MyStruct
{
    public void ProcessData(object data)
    {
        if (Data != null)
            Data = data;
    }
    public object Data { get; private set; }
}