我应该总是使用AndAlso和OrElse运算经营者?经营者、AndAlso、OrElse

2023-09-02 11:52:24 作者:夕照乔木

是否有过的,我不希望使用 AndAlso 运营商,而不是 运营商? …或者,我不希望使用 OrElse运算 运营商,而不是 运营商?

Is there ever a circumstance in which I would not want to use the AndAlso operator rather than the And operator? …or in which I would not want to use the OrElse operator rather than the Or operator?

推荐答案

从 MSDN :

短路权衡

的短路可以提高通过不评估的前pression无法改变的逻辑操作的结果表现。但是,如果前pression执行其他操作,短路跳过这些操作。例如,如果EX pression包括调用一个函数的过程,该过程将不会调用如果EX pression短路,并包含在功能的任何额外code不运行。如果你的程序逻辑依赖于任何额外的code,你应该避免短路操作。的

 
精彩推荐