tags:

views:

121

answers:

2
+5  A: 

No, VB.Net has no such blanket scoping modifiers. You can simulate them by using an empty loop like the following.

Loop
  ...
Until False

However it will still not permit you to redefine a variable with the same name. In VB.Net (and C#) it is not legal to define a variable in a nested scope with the same name as a variable in an outer scope.

JaredPar
IMO it's good not to have this: 9 times out of 10 it means that could should be in it's own method anyway.
Joel Coehoorn
@Joel, completely agree. I've been bitten several times by double defined variables in C++. It's especially problematic in old code bases with very large methods which have been patch worked for years.
JaredPar
+5  A: 

You can use an empty With block:

With Nothing

    Dim x = 1

    Console.WriteLine("X = " + x.ToString())

End With

' ERROR! x is out of scope at this point. '
Console.WriteLine(x)

Since With is only a syntactic sugar it might be better than using looping statements.

chakrit