Skip to main content

Static constructors must be parameterless

In This Article

CodeRush Classic shows the Static constructors must be parameterless code issue if a static constructor has parameters.

#Fix

Remove the parameters from the static constructor declaration.

#Purpose

Highlights the static constructor declarations, which would cause the A static constructor must be parameterless compilation error.

#Example

public static class MyClass
{
    static MyClass(string text)
    {
        Text = text;
    }
    public static string Text { get; set; }
}

Fix:

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