嵌套 using 语句

发布于 2024-09-11 06:45:18 字数 407 浏览 1 评论 0原文

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谜兔 2024-09-18 06:45:18

像这样:

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

Like this:

Using a As New Thingy(), _
      b As New OtherThingy()
        ...
End Using
长发绾君心 2024-09-18 06:45:18

好吧,你可以这样做:

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

Well, you can do:

Using w1 = File.CreateText("W1"), w2 = File.CreateText("W2")
    ' Code goes here. '
End Using
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文