代码之家  ›  专栏  ›  技术社区  ›  Hans Olsson

嵌套using语句

  •  26
  • Hans Olsson  · 技术社区  · 15 年前

    this 博客文章,在C#你可以嵌套 using 声明如下:

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

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

    2 回复  |  直到 12 年前
        1
  •  41
  •   Ry- Vincenzo Alcamo    12 年前

    这样地:

    Using a As New Thingy(), _
          b As New OtherThingy()
            ...
    End Using
    
        2
  •  5
  •   Dan Tao    15 年前

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