30

正如 Eric Gunnerson 在这篇博文中所展示的,在 C# 中,您可以将using语句嵌套为:

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

在 VB.Net 中有类似的方法吗?我想避免太多的缩进级别。

4

2 回答 2

42

像这样:

Using a As New Thingy(), _
      b As New OtherThingy()
        ...
End Using
于 2010-07-27T15:52:28.207 回答
5

好吧,你可以这样做:

Using w1 = File.CreateText("W1"), w2 = File.CreateText("W2")
    ' Code goes here. '
End Using
于 2010-07-27T15:56:28.790 回答