Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS0171 

Error Message

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

A constructor in a struct must initialize all fields in the struct. For more information, see Constructors (C# Programming Guide).

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();
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft