你可以使用一个空With块:
With Nothing
Dim x = 1
Console.WriteLine("X = " + x.ToString())
End With
' ERROR! x is out of scope at this point. '
Console.WriteLine(x)
Run Code Online (Sandbox Code Playgroud)
因为With它只是一个语法糖,它可能比使用循环语句更好.
不,VB.Net没有这样的毯子范围修饰符.您可以使用如下所示的空循环来模拟它们.
Loop
...
Until False
Run Code Online (Sandbox Code Playgroud)
但是,它仍然不允许您重新定义具有相同名称的变量.在VB.Net(和C#)中,在嵌套作用域中定义一个与外部作用域中的变量同名的变量是不合法的.
| 归档时间: |
|
| 查看次数: |
240 次 |
| 最近记录: |