Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS0843
Collapse the table of content
Expand the table of content

Compiler Error CS0843

Backing field for automatically implemented property 'name' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer.

To assign a value to an automatically-implemented property from a constructor, you must first invoke the default constructor to create the object.

To correct this error

  • Add a call to the default constructor in a constructor initializer as shown in the following example. Note the use of : this(). For more information, see this (C# Reference).

The following code generates CS0843:

// cs0843.cs
struct S
{
    public int AIProp { get; set; }
    public S(int i){} //CS0843
    // Try the following lines instead.
   // public S(int i) : this()
   // {
   //     AIProp = i;
   // }
}

class Test
{
    static int Main()
    {
        return 1;
    }
}
Show:
© 2015 Microsoft