在VB中,Select Case语句用于根据表达式的值来执行不同的代码块。
语法:
Select Case expression
Case value1
' 执行代码块1
Case value2
' 执行代码块2
Case value3
' 执行代码块3
...
Case Else
' 执行默认代码块
End Select
示例:
Dim num As Integer = 3
Select Case num
Case 1
Console.WriteLine("Number is 1")
Case 2
Console.WriteLine("Number is 2")
Case 3
Console.WriteLine("Number is 3")
Case Else
Console.WriteLine("Number is not 1, 2, or 3")
End Select
输出:
Number is 3
注意事项: