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

前端 未结 11 1656
无人及你
无人及你 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:04

    You have the classic switch statement :

    switch(a) {
        case x:
        case y:
        case z:
            // Do stuff
            break;
    }
    

提交回复
热议问题