C#如果法定执行顺序 [英] C# If statment execution order

查看:59
本文介绍了C#如果法定执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中(exp1&& exp2&& exp3)


是否从左到右(exp1 -exp2 -exp3)进行评估?或者权利

剩下(exp3 -exp2 -exp1)?或者即使

exp1被证明是假的,它会执行所有这些吗?


谢谢:)

In C# if(exp1 && exp2 && exp3)

Does it evalutate left to right (exp1 -exp2 -exp3)? or right to
left (exp3 -exp2 -exp1)? Or would it execute all of them even if
exp1 turned out to be false?

Thanks :)

推荐答案

" NvrBst" < nv **** @ gmail.com写信息

news:11 ********************** @ o11g2000prd.googlegr oups.com ...
"NvrBst" <nv****@gmail.comwrote in message
news:11**********************@o11g2000prd.googlegr oups.com...

在C#if(exp1&& exp2&& exp3)


它是否从左到右评估(exp1 -exp2 -exp3)?或者权利

剩下(exp3 -exp2 -exp1)?或者即使

exp1被证明是假的,它会执行所有这些吗?
In C# if(exp1 && exp2 && exp3)

Does it evalutate left to right (exp1 -exp2 -exp3)? or right to
left (exp3 -exp2 -exp1)? Or would it execute all of them even if
exp1 turned out to be false?



从左到右。

Left to right.


>

谢谢:)
>
Thanks :)



6月13日上午9:14,NvrBst< nvr ... @ gmail.comwrote:
On Jun 13, 9:14 am, NvrBst <nvr...@gmail.comwrote:

在C#中(exp1&& exp2&& exp3)


是否从左到右评估(exp1 -exp2 -exp3) ?或者权利

剩下(exp3 -exp2 -exp1)?或者即使

exp1被证明是假的,它会执行所有这些吗?
In C# if(exp1 && exp2 && exp3)

Does it evalutate left to right (exp1 -exp2 -exp3)? or right to
left (exp3 -exp2 -exp1)? Or would it execute all of them even if
exp1 turned out to be false?



它将评估exp1,然后只有当它'是真的它才会评估exp2,

然后只有当它'真的它会评估exp3。


换句话说,它直观地正确地表达了它。事情。


Jon

It will evaluate exp1, then only if that''s true will it evalute exp2,
then only if that''s true will it evaluate exp3.

In other words, it does the intuitively "right" thing.

Jon




此外它停止评估是否有表达式是错误的反对

&运算符,例如:


String nul = null;

String test =" test";

if(nul!= null&& test.Length nul.Length)

Response.Write(" test");


不会导致异常,而这将:


String nul = null;

String test =" test";

if(nul!= null & test.Length nul.Length)

Response.Write(test);


因为后者会尝试评估表达式测试。长度>

nul.Length,其中nul = null。


Morten

AND moreover it stops evaluating if an expression is false opposed to
the & operator, e.g.:

String nul = null;
String test = "test";
if (nul != null && test.Length nul.Length)
Response.Write("test");

will NOT result in an exception, while this will:

String nul = null;
String test = "test";
if (nul != null & test.Length nul.Length)
Response.Write("test");

because the latter will try to evaluate the expression test.Length >
nul.Length, where nul = null.

Morten


这篇关于C#如果法定执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆