order - Does c# support chaining && in an if statement or do they have to be nested? -
this question has answer here:
if use following code,
if (obj.contactdetail != null && obj.contactdetail.id != guid.empty) will null reference error on second half (.id) or behave javascript , fall out of if on first half of comparison.
i know has been answered, don't know terms use up. sry.
that's called short-circuit evaluation , yes, && operator evaluates second condition if first not false.
msdn:
the conditional-and operator (&&) performs logical-and of bool operands, only evaluates second operand if necessary.
the operation
x && ycorresponds operationx & yexcept if x false, y not evaluated, because result of , operation false no matter value of y is. this known "short-circuit" evaluation. conditional-and operator cannot overloaded, overloads of regular logical operators , operators true , false are, restrictions, considered overloads of conditional logical operators.
Comments
Post a Comment