Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0573 

Error Message

'field declaration' : cannot have instance field initializers in structs

You cannot initialize an instance field of a struct. Fields of value types will be initialized to their default values, and reference-type fields will be initialized to null.

Example

The following sample generates CS0573:

// CS0573.cs
namespace x
{
    public class clx
    {
        public static void Main()
        {
        }
    }

    public struct cly
    {
        clx a = new clx();   // CS0573
        // clx a;            // OK
        int i = 7;           // CS0573
        // int i;            // OK
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft