开发者

if (iAmNull != null && iAmNull.Length == 6) Do(); [duplicate]

This question already has answers here: Closed 11 years ago. 开发者_运维知识库

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜