鉴于典型的编码咒语是“不要在方法调用中诱发副作用”。并且唯一的原因(我知道 - 请指教我,如果我错了)不使用短路操作符的时候,是在随后的代码中依赖方法调用的副作用。为什么C#和VB.NET等语言中的默认运算符不是短路版本?为什么不将短路操作员设为默认
IE:
if (Method1() & Method2()) {
}
if Method1 And Method2 then
End if
if (Method1() | Method2()) {
}
if Method1 Or Method2 then
End if
实际上(默认)意味着
if (Method1() && Method2()) {
}
if Method1 AndAlso Method2 then
End if
if (Method1() || Method2()) {
}
if Method1 OrElse Method2 then
End if
C#确实使用短路评估。这就是说,这个问题看起来像是一个重复的http://stackoverflow.com/questions/1445867/why-would-a-language-not-use-short-circuit-evaluation – jjlin 2012-02-05 06:09:16