我正在使用VB.NET进行编码。
目前,我将对象初始化和使用封装在Try/Catch块中,然后在Finally块中拆除(dispose、close、set to nothing)。问题是,C#中的“using”块很容易使用,并且可以清理我的代码。
是否存在VB.NET等效的方法?或者我的Finally块拆除解决方案是唯一的方法?
它们是一样的,只是:
Using conn As New SqlConnection
....
End Using
http://msdn.microsoft.com/en-us/library/htd05whh(VS.80).aspx
Public Sub setbigbold(ByVal c As Control)
Using nf As New System.Drawing.Font("Arial", 12.0F, _
System.Drawing.FontStyle.Bold)
c.Font = nf
c.Text = "This is 12-point Arial bold"
End Using
End Sub