Will all methods in a logical expressions be executed?

前端 未结 5 1951
我在风中等你
我在风中等你 2021-01-27 17:35

In C#, given the two methods

 bool Action1(object Data);
bool Action2(object Data);

that are used in an if statement like this:

5条回答
  •  粉色の甜心
    2021-01-27 17:57

    Action2 will not be called if Action1 returns true, due to the rules of short-circuit evaluation. Note that this is a runtime optimization, not a compile-time optimization.

提交回复
热议问题