if (iAmNull != null && iAmNull.Length == 6) Do(); [duplicate]
Possible Duplicate:
What happens if the first part of an if-structure is false?
if the first criterion yields false in an AND, is the second condition evaluated at all in c# ?
i.e. is a NullException thrown in this example?
if (iAmNull != null && iAmNull.Length == 6) Do();
No the second condition is not evaluated because you are using the short-circuit && operator.
From Wikipedia:
Short-circuit evaluation, minimal evaluation, or McCarthy evaluation denotes the semantics of some Boolean operators in some programming languages in which the second argument is only executed or evaluated if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall value must be true.
No, the logical operators have short-circuit evaluation.
精彩评论