Yes, a()
will always be evaluated.
Since the condition is evaluated from left to right, a()
will always be evaluated, but b != null
will only be evaluated if a()
returns true
.
Here’s an exact specification reference for you, from the C# Language Specification version 3.0. My emphases and elisions.
7.11.1 Boolean conditional logical operators
When the operands of
&&
or||
are of typebool
[…] the operation is processed as follows:
- The operation
x && y
is evaluated asx ? y : false
. In other words,x
is
first evaluated and converted to type bool. Then, ifx
is true, y is
evaluated and converted to type bool, and this becomes the result of
the operation. Otherwise, the result of the operation is false.