Let's say we have the following C# code:
public bool F(int? a, int? b) {
return a == b;
}
then the compiler converts it to
public bool F(Nullable<int> a, Nullable<int> b) {
Nullable<int> num = a;
Nullable<int> num2 = b;
return (num.GetValueOrDefault() == num2.GetValueOrDefault()) & (num.HasValue == num2.HasValue);
}
Notice that &
is used instead of $$
. But isn't $$
more appropriate and efficient to use because it evaluates the right-hand operand only if it's necessary. If num.GetValueOrDefault() == num2.GetValueOrDefault()
is false then there is no need to check num.HasValue == num2.HasValue
, but &
has to check both. So why the compiler choose to use &
instead of &&
?