Skip to main content

Constructor must declare a body

In This Article

CodeRush Classic shows the Constructor must declare a body code issue if a constructor does not declare a body.

#Fix

Declare a body for the constructor.

#Purpose

Highlights the constructor declaration statements, which would cause the Must declare a body because it is not marked abstract, extern or partial compilation error.

#Example

public class MyClass
{
    public MyClass(string name);
    public string Name { get; set; }
    public int Value { get; set; }
}

Fix:

public class MyClass
{
    public MyClass(string name)
    {
        Name = name;
    }
    public string Name { get; set; }
    public int Value { get; set; }
}