I have next expression :
var max = items.FirstOrDefault(x => x.Key > date).Value;
if (max == null)
{
max = items.FirstOrDefault(x => x.Key < date).Value;
}
I would like to shorten it this way :
var max =
items.FirstOrDefault(x => x.Key > date).Value ?? // this line
items.FirstOrDefault(x => x.Key < date).Value;
And here is the question : is C# smart enough to not execute line before ternary operator twice?
In other words, I hope that ternary operator will not be converted to something like this :
var max =
items.FirstOrDefault(x => x.Key > date).Value == null ?
items.FirstOrDefault(x => x.Key > date).Value :
items.FirstOrDefault(x => x.Key < date).Value;