Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0171

Field 'field' must be fully assigned before control leaves the constructor

A constructor in a struct must initialize all fields in the struct.

The following sample generates CS0171:

// CS0171.cs
struct MyStruct
{
   MyStruct(int initField)   // CS0171
   {
      // i = initField;      // uncomment this line to resolve this error
   }
   public int i;
}

class MyClass
{
   public static void Main()
   {
      MyStruct aStruct = new MyStruct();
   }
}
Show:
© 2014 Microsoft