C# does not allow an instance field initializer to reference another field. For instance this code is not valid :
class A
{
string s1 = "";
string s2 = s1;
}
because "s2" references "s1".
But why this is not permitted ?
My first thought was that the C# specs do not guarantee any initialization order but according to the specs the order is the order of declaration :
The variable initializers are executed in the textual order in which they appear in the class declaration.
So if the order is deterministic what could be the pitfalls of this kind of code ?
Thanks in advance for your help.
EDIT :
According to the answers of Hps, 0xA3 and Peter :
order of initialization in inheritance scenario could be very confusing,
implementing such a feature would require some resources from the compiler development team for little benefit,
it's not possible to use method or properties for logical reasons (thanks Peter), so for consistency the same is true for fields.