Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0188 

Error Message

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. For more information, see Using Structs (C# Programming Guide).

The following sample generates CS0188:

// CS0188.cs
// compile with: /t:library
namespace MyNamespace
    class MyClass
        struct S
            public int a;

            void Foo()

            S(int i)
                // a = i;
                Foo();  // CS0188
        public static void Main()
        { }


Community Additions

© 2014 Microsoft