Will all methods in a logical expressions be executed?

前端 未结 5 1995
我在风中等你
我在风中等你 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 18:02

    Action2() will only be called if Action1() returns false

    This is conceptually similar to

    if (Action1(Data))
    {
        PerformOtherAction();
    } 
    else if (Action2(Data))
    {
        PerformOtherAction();
    } 
    

提交回复
热议问题