Compiler Error CS0573

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

You can't 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.

Note

Beginning with C# 10, you can initialize a struct's instance field or property at its declaration. For more information, see the Struct initialization and default values section of the Structure types article.

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  
    }  
}