开发者

Nested using statements

开发者 https://www.devze.com 2023-01-08 21:18 出处:网络
As Eric Gunnerson shows in this blog post, in C# you can nest using statements as: using (StreamWriter w1 = File.CreateText(\"W1\"))

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

using (StreamWriter w1 = File.CreateText("W1"))
u开发者_如何学编程sing (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.


Like this:

Using a As New Thingy(), _
      b As New OtherThingy()
        ...
End Using


Well, you can do:

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

精彩评论

暂无评论...
验证码 换一张
取 消