Why the following code returns false?
public static void Main()
{
bool? someCondition = true;
bool someConditionOverride = false;
bool? result = someCondition ?? someConditionOverride ? false : (bool?)null;
Console.WriteLine(result);
}
I was exprecting the result will be true, since someCondition is not null and ?? operator will return true. However looks like right operand is calculated first and the left part is simply ignored.
Adding brackets fix the confusion:
bool? result = someCondition ?? (someConditionOverride ? false : (bool?)null)
And the result will be true. However I am still curious why left part had been ignored in the first example.