Block-scope for local variable

scope, vb.net

Solution

With `Option Strict On`, that'd have to be `If True Then`, but the more preferred option (as far as I have seen) is `Do ... Loop While False`.

But, no there is no syntax like a simple `Begin ... End` (or `{ ...}`).

If you can work with an `IDisposable`, and have it disposed at the end of the block, `Using newVariable = AnIDisposable` gives you the closest to what you're describing, but like I said, it is disposed at the end.

Problem

Is there a better way to create an arbitrary block in VB.Net to limit the scope of a local variable? If have tried "If 1 Then", but it just looks kludgy. ``` If 1 Then Dim table = InputParameter1 Dim new_row = table.AddRow new_row.field(1) = InputParameter3.user_value End If ``` I just don't want to have `table` and `new_row` accessible later in the procedure.

Original source