“if (a() && b != null)” will “a()” always be evaluated?

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 type bool […] the operation is processed as follows:

  • The operation x && y is evaluated as x ? y : false. In other words, x is
    first evaluated and converted to type bool. Then, if x 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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)