What is the VB.NET equivalent to C#'s 'using' block

前端 未结 4 1214
故里飘歌
故里飘歌 2021-01-01 10:49

I am coding in 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 F

相关标签:
4条回答
  • 2021-01-01 11:37

    Er, Using ... End Using

    See MSDN for more info

    0 讨论(0)
  • 2021-01-01 11:39

    It's the same, it's just:

    Using conn As New SqlConnection
        ....
    End Using
    
    0 讨论(0)
  • 2021-01-01 11:54

    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
    
    0 讨论(0)
  • 2021-01-01 11:55

    Here is another StackOverflow question that deals with the exact same issue. If I'm not mistaken it's used in a very similar, if not the exact same, way as in C# though.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题