2010-07-27 141 views
24

正如埃裏克Gunnerson顯示this博客文章,在C#中,你可以嵌套using語句:嵌套using語句

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

是否有類似的辦法做到這一點在VB.Net?我想避免太多縮進級別。

回答

34

像這樣:

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

嗯,你可以這樣做:

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