Why use this to initialize the structure property through the constructor? Without: this () will fail when compiling

struct T { public T(int u) : this() { this.U = u; } public int U { get; private set; } } 

1 answer 1

When defining autoproperty, a private field is created in the class / structure in which the value is stored. The property is only two functions: get - to get the value and set to be set.

Thus, without calling the default constructor ( :this() ), an attempt is made to call the set function to set the field, which is prohibited, since the field structure must be initialized before referencing them.

In the case of a default constructor call, the field is initialized in it with a default value.