Skip to main content

Static class cannot contain protected member

In This Article

CodeRush Classic shows the Static class cannot contain protected member code issue if a protected member is declared in a static class.

#Fix

Use any access modifier, except protected and protected internal in the static class.

#Purpose

Highlights the static class member declarations, which would cause the Static class cannot contain protected members compilation error.

#Example

public static class MyClass
{
    protected static float GetSquare(float a, float b)
    {
        return a * b;
    }
}

Fix:

public static class MyClass
{
    private static float GetSquare(float a, float b)
    {
        return a * b;
    }
}