Using in VB.NETI have not touched VB.NET since early in .NET Beta 1, so I am a bit rusty. One thing I was happy to find is support for using statements in VB.NET 2005. It took me a try or two to figure out the syntax, so I figured I would post it here for future reference. Public Class Class1 Public Sub Go() Using sw As StreamWriter = New StreamWriter("C:\hey.txt") sw.Write("HEY") End Using End Sub End Class via MSDN: "The using statement obtains one or more resources, executes a statement, and then disposes of the resource." For those unfamailar with a using statement, you can use for classes which implement IDisposable. As soon as the variable defined in the using section goes out of scope, Dispose is called.
Public Class Class1
Public Sub Go() Using sw As StreamWriter = New StreamWriter("C:\hey.txt") sw.Write("HEY") End Using End Sub
End Class
via MSDN: "The using statement obtains one or more resources, executes a statement, and then disposes of the resource."
For those unfamailar with a using statement, you can use for classes which implement IDisposable. As soon as the variable defined in the using section goes out of scope, Dispose is called.
Dim sw as New StreamWriter("C:\hey.txt") Try sw.Write("HEY") Finally sw.Dispose() End Try