Compiler Error CS0188

The 'this' object cannot be used before all of its fields are assigned to

All fields in a struct have to be assigned by a constructor before the constructor can call a method in the struct.

If you see this error when trying to initialize a property in a struct constructor, the solution is to initialize the backing field of that property directly instead of the property itself.

Example

The following sample generates CS0188:

// CS0188.cs  
// compile with: /t:library  
namespace MyNamespace  
{  
    class MyClass  
    {  
        struct S  
        {  
            public int a;  
  
            void MyMethod()  
            {  
            }  
  
            S(int i)  
            {  
                // a = i;  
                MyMethod();  // CS0188  
            }  
        }  
        public static void Main()  
        { }  
  
    }  
}  

See also