如何使用 SELECT CASE 和 TO 使用 INTEGER
How to use SELECT CASE with TO using INTEGER
我正在尝试在我的代码中使用 SELECT CASE
。
但即使变量的值也在SELECT CASE
中的设定值之间
它没有命中那种情况下的代码。
例如:
Dim i as Integer = 27
Select Case i
Case 3 To 33
'This would be Hit
Case 34 To 50
'Some Code
Case Else
End Select
现在。下面注释中的代码这会被命中无法执行。
如何解决?
此致,
要么是您弄错了,要么是您的系统出现了问题。我刚刚在控制台项目中测试了这段代码:
Module Module1
Sub Main()
Dim i As Integer = 27
Select Case i
Case 3 To 33
'This would be Hit
Console.WriteLine("i is in the range 3 to 33")
Case 34 To 50
'Some Code
Console.WriteLine("i is in the range 34 to 50")
Case Else
Console.WriteLine("i is in not in either range")
End Select
Console.ReadLine()
End Sub
End Module
我看到了留言:
i is in the range 3 to 33
符合预期。
我正在尝试在我的代码中使用 SELECT CASE
。
但即使变量的值也在SELECT CASE
中的设定值之间
它没有命中那种情况下的代码。
例如:
Dim i as Integer = 27
Select Case i
Case 3 To 33
'This would be Hit
Case 34 To 50
'Some Code
Case Else
End Select
现在。下面注释中的代码这会被命中无法执行。
如何解决?
此致,
要么是您弄错了,要么是您的系统出现了问题。我刚刚在控制台项目中测试了这段代码:
Module Module1
Sub Main()
Dim i As Integer = 27
Select Case i
Case 3 To 33
'This would be Hit
Console.WriteLine("i is in the range 3 to 33")
Case 34 To 50
'Some Code
Console.WriteLine("i is in the range 34 to 50")
Case Else
Console.WriteLine("i is in not in either range")
End Select
Console.ReadLine()
End Sub
End Module
我看到了留言:
i is in the range 3 to 33
符合预期。