【发布时间】:2011-12-21 08:48:42
【问题描述】:
我有一堆方法都返回一个布尔值。
如果一个方法返回 false,则调用以下方法没有任何价值,尤其是其中一些是“昂贵”的操作。
哪个效率更高?
bool result = method1();
if (result) result = method2();
if (result) result = method3();
return result;
或
return method1() && method2() && method3();
据我了解,一旦其中一种方法返回 false,第二种形式就应该停止评估,对吧?
【问题讨论】:
标签: c# .net boolean-operations