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

后端 未结 7 1189

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
    
    0 讨论(0)
提交回复
热议问题