Given that it’s valid to write
a = b = c = 2;
It would also be nice, rather than
bool allTwo = a == 2 && b == 2 && c == 2;
to instead write
bool allTwo = a == b == c == 2;
But I can’t since a == b evaluates to a boolean which can’t then be compared to an integer.
Is there a language-design reason it has been implemented this way?
The type of the expression
a == bis boolean, so you would either have to break a rule that an expression means the same thing whatever its context, or have n-ary == operators so thata == b == cis parsed as(== a b c)rather than(== (== a b) c). Which then means you need to have(a == b) == cto compare the boolean c to the result of(a == b), which is OK, but not the simple C style of grammar which C# is in the tradition of.