正如Eric Gunnerson在this博文中所示,在C#中你可以将using
语句嵌套为:
using (StreamWriter w1 = File.CreateText("W1"))
using (StreamWriter w2 = File.CreateText("W2"))
{
// code here
}
在VB.Net中有类似的方法吗?我想避免太多的缩进级别。
答案 0 :(得分:38)
像这样:
Using a As New Thingy(), _
b As New OtherThingy()
...
End Using
答案 1 :(得分:5)
嗯,你可以这样做:
Using w1 = File.CreateText("W1"), w2 = File.CreateText("W2")
' Code goes here. '
End Using