What is the VB.NET select case statement logic with case OR-ing?

后端 未结 5 996
一个人的身影
一个人的身影 2021-02-06 20:42

I\'m using an Or statement in my case expression.

Even though I have a value within this range, it didn\'t find a match. Why not?

Example Code:<

5条回答
  •  悲&欢浪女
    2021-02-06 21:20

    JaredPar has it right but you can also use the To construct

    Select Case 2
        Case 0,1
        Case 2 To 3
            Console.WriteLine("Hit")
    End Select
    

    This would be 0 or 1 do nothing, 2 or 3 print Hit...The To construct is a range...

    Here's the MSDN

提交回复
热议问题