“else if()” versus multiple “if()”s in C#

后端 未结 10 1814
一个人的身影
一个人的身影 2021-01-03 21:51

How do these practically differ?

// Approach one
if (x == 1)
    DoSomething();
else if (x == 2)
    DoSomethingElse();

// Approach two
if (x == 1)
    DoSo         


        
10条回答
  •  星月不相逢
    2021-01-03 22:34

    If x is modified by multiple threads it is possible that DoSomething() and DoSomethingElse() will both get called with the second approach

提交回复
热议问题