[英]What is the VB.NET equivalent to C#'s 'using' block
I am coding in VB.NET. 我在VB.NET编码。
Currently, I am enclosing object initialization and usage in a Try/Catch block and then tear it down (dispose, close, set to nothing) in the Finally block. 目前,我在Try / Catch块中包含对象初始化和使用,然后在Finally块中将其拆除(dispose,close,设置为nothing)。 The problem is, a C# 'using' block is so easy to use and would clean things up in my code.
问题是,C#'using'块很容易使用,并且会在我的代码中清理它们。
Is there a VB.NET equivalent? 是否有VB.NET等价物? Or is my Finally block tear-down solution the only way?
或者是我的最终阻止解决方案唯一的方法?
It's the same, it's just: 它是一样的,它只是:
Using conn As New SqlConnection
....
End Using
http://msdn.microsoft.com/en-us/library/htd05whh(VS.80).aspx 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.