Skip to main content

Static constructors cannot have access modifiers

In This Article

CodeRush Classic shows the Static constructors cannot have access modifiers code issue if a static constructor has an access modifier.

#Fix

Remove the access modifier from the static constructor declaration.

#Purpose

Highlights the static constructor declarations, which would cause the Access modifiers are not allowed on static constructors compilation error.

#Example

public static class MyClass
{
    public static MyClass()
    {
        Text = String.Empty;
    }
    public static string Text { get; set; }
}

Fix:

public static class MyClass
{
    static MyClass()
    {
        Text = String.Empty;
    }
    public static string Text { get; set; }
}