I think you are a little doubtful about your starting point.
There is nothing magical about a = b = c = 2 to suggest that a == b == c == 2 should work the way you want - in fact, more - on the contrary.
An assignment operator is defined only for two operands and returns the given value. A line of them simply passes the value from each statement to the following:
1: a = (b = (c = 2)); 2: a = (b = (2)); 3: a = (2);
So the same is true for a == b == c == 2 :
1: bool allTwo = (a == (b == (c == 2))); 2: bool allTwo = (a == (b == ([Boolean]))); 3: bool allTwo = (a == ([Boolean])); 4: bool allTwo = ([Boolean]);
So the technical reason is that C# does not contain a definition for a special call for a statement string.
Regarding language design and implementation, the reason is probably to prevent ambiguity and additional complexity. Although you may need a == b == c == 2 , which is now defined as all equal , on the next line you might really need it to be running now. How should behavior be distinguished? And would it really be worth the effort to implement?
Or is a == 2 && b == 2 really that bad ?;)
source share