Check if a variable is in an ad-hoc list of values

后端 未结 7 1216

Is there a shorter way of writing something like this:

if(x==1 || x==2 || x==3) // do something

Wha

7条回答
  •  我在风中等你
    2020-12-08 19:08

    This answer refers to a possible future version of C# ;-) If you consider switching to Visual Basic, or if Microsoft finally decides to introduce the Select Case statement to C#, it would look like this:

    Select Case X
        Case 1, 2, 3
        ...
    End Select
    

提交回复
热议问题