Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 case 语句中声明的变量是否是该 case 语句的本地变量 -
例如,在下面的代码中,这样使用 z 是否安全?还是编译器只是将 z 放在过程范围内?
Select Case x Case 6 Dim z As Integer = 6 Case 7 Dim z As Integer = 7 End Select
这样做是安全的。您可以通过尝试编译以下内容来测试它:
Dim x As Integer Select Case x Case 6 Dim z As Integer = 6 Case 7 Dim z As Integer = 7 End Select Console.Write(z)
并注意你会得到一个编译错误。
当然,它会降低 IMO 的可读性。无论如何,也许您应该在程序开始时声明它。