在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
注意事項: