VB.NET Stacking Select Case Statements together like in Switch C#/Java

后端 未结 1 764
迷失自我
迷失自我 2021-02-18 19:37

Seems If I stack the Cases together they don\'t work as one. Since VB.NET Cases don\'t require the use of Exit Select / Return it seems to automatically put that ev

1条回答
  •  灰色年华
    2021-02-18 19:52

    Your understanding is correct. VB will not "fall through".

    Specify a single Case and separate each expression with a comma:

    Select Case Test
        Case 11, 12, 13
            MsgBox.Show("Could be 11 or 12 or 13?")
    End Select
    

    Alternatively, you could use a range with the To keyword to accomplish the same thing:

    Select Case Test
        Case 11 To 13
            MsgBox.Show("Could be 11 or 12 or 13?")
    End Select
    

    For more information, see the documentation.

    0 讨论(0)
提交回复
热议问题