【问题标题】:Nested using statements嵌套 using 语句
【发布时间】:2011-03-21 16:37:33
【问题描述】:

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

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

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

【问题讨论】:

    标签: vb.net using-statement


    【解决方案1】:

    像这样:

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

    【讨论】:

      【解决方案2】:

      好吧,你可以这样做:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-18
        • 2010-11-22
        • 1970-01-01
        • 2014-06-05
        • 2014-04-04
        • 2011-12-27
        • 1970-01-01
        相关资源
        最近更新 更多