C#. Do if( a == (b or c or d)). Is it possible?

前端 未结 11 1764
无人及你
无人及你 2021-02-02 09:31

Is there another way to write something like this:

if (a == x || a == y || a == z)

One way that I found is doing it like this:

         


        
11条回答
  •  無奈伤痛
    2021-02-02 10:10

    For instance, your logic is like that:

    if(a==x || a== y|| a==z)
    {
        DoSomething();
    } 
    else
    {
       DoOtherThings();
    }
    

    will equivalent to:

    if(a!=x&& a != y && a!= z)
    {
       DoOtherThings();
    }
    else
    {
       DoSomething();
    }
    

    Cheers.

提交回复
热议问题