tags:

views:

83

answers:

4

As Eric Gunnerson shows in this blog post, in C# you can nest using statements as:

using (StreamWriter w1 = File.CreateText("W1"))
using (StreamWriter w2 = File.CreateText("W2"))
{
    // code here
}

Is there a similar way to do it in VB.Net? I want to avoid too many indentation levels.

A: 

Unfortunately it seems that you have to nest the Using in VB...

http://www.pluralsight-training.net/community/blogs/fritz/archive/2005/04/28/7834.aspx

nonnb
A: 

The following post may offer some guidance.

http://stackoverflow.com/questions/1374186/using-statement-with-more-than-one-system-resource

Garett
+2  A: 

Like this:

Using a As New Thingy(), _
      b As New OtherThingy()
        ...
End Using
SLaks
+2  A: 

Well, you can do:

Using w1 = File.CreateText("W1"), w2 = File.CreateText("W2")
    ' Code goes here. '
End Using
Dan Tao