"the left part is simply ignored"? How likely do you really think that is?
Operator precedence dictates that your first version is parsed like so:
bool? result = (someCondition ?? someConditionOverride)
? false
: (bool?)null;
someCondition
isn't null, and it is true. Therefore, this expression evaluates as true
:
(someCondition ?? someConditionOverride)
So we get the ?
branch, and the whole expression returns false
, just like you told it to.
Adding the brackets that you added completely changes the meaning of the expression. It fixes your confusion, in a limited sense, by bringing the actual meaning of the expression in line with your original intent; but the compiler is never confused. In C#, compiler confuses you.
To reduce my own confusion, I never rely on operator precedence. I parenthesize everything. If I had designed the language, the grammar would require it (unless Eric comes by and tells me why that's actually not such a good idea after all, for some reason that will make perfect sense to me once Eric explains it).
UPDATE: Prediction validated: Eric came by and said that too many people would find it ridiculous to have to parenthesize a + b * c
, and if you allow that, there's no reasonable way to define the exceptions. Well, if they won't tolerate being forced to parenthesize everything, they won't, however much I think they should.
Best Answer
Will work :)
It parsed it this way:
which does not make any sense.