A few code samples might help clarify this better:
// This works because you assign both fields before accessing anything
EmpStruct empStruct;
empStruct.SecondNumber = 2;
empStruct.firstNumber = 1; // I made this public
empStruct.FirstNumber = 3;
Console.WriteLine(empStruct.FirstNumber);
Console.WriteLine(empStruct.SecondNumber);
// This fails because you can't use properties before assigning all the variables
EmpStruct empStruct;
empStruct.SecondNumber = 2;
empStruct.FirstNumber = 3;
// This works because you are only accessing a field that the compiler knows you've assigned
EmpStruct empStruct;
empStruct.SecondNumber = 2;
Console.WriteLine(empStruct.SecondNumber);
// This fails because you haven't assigned the field before it gets accessed.
EmpStruct empStruct;
Console.WriteLine(empStruct.SecondNumber);
The point is, the compiler knows exactly what will happen when you assign a field. But when you assign a property, that might access any number of other fields on the struct
. The compiler doesn't know for sure. So it requires you to have all the fields assigned before you can access a property.