【发布时间】:2011-02-11 14:47:39
【问题描述】:
以下哪种方法最好?或者两者都具有相同的效果?
Dim carrierName As String
Dim someotherName As String
Dim anotherOne As String
Using oDa As New MyCompany.DataAccess.MyModule
carrierName = oDa.GetCarrierName(itemNumber)
End Using
Using oDa As New MyCompany.DataAccess.MyModule
someotherName = oDa.GetSomeOtherName(itemNumber,1)
End Using
Using oDa As New MyCompany.DataAccess.MyModule
anotherOne = oDa.GetAnotherName("somevalue")
End Using
或
Using oDa As New MyCompany.DataAccess.MyModule
carrierName = oDa.GetCarrierName(itemNumber)
someotherName = oDa.GetSomeOtherName(itemNumber,1)
anotherOne = oDa.GetAnotherName("somevalue")
End Using
【问题讨论】:
-
呃,这是 VB.NET,而不是 C#...我已经进行了相应的编辑。
-
他们没有做同样的事情。第一个创建三个
MyCompany.DataAccess.MyModule对象,而第二个只创建一个。这将取决于MyCompany.DataAccess.MyModule的行为方式。测量一下怎么样? -
为什么要一遍又一遍地创建和销毁相同的东西?只使用一个“使用”
标签: vb.net performance using-statement