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

后端 未结 5 1001
一个人的身影
一个人的身影 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:00

    This will allow you to perform "something" in the case of 0, "something else" in the case of 1, "hit" in the case of 2 or 3 or "hit else" otherwise.

    Select Case 2
        Case 0
            Console.WriteLine("something")
        Case 1
            Console.WriteLine("something else")
        Case Is 2 To 3
            Console.WriteLine("hit")
        Else
            Console.WriteLine("hit else")
     End Select
    

提交回复
热议问题