The Artima Developer Community
Sponsored Link

.NET Buzz Forum
'Using' statement added to VB in Whidbey release...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Duncan Mackenzie

Posts: 689
Nickname: duncanma
Registered: Aug, 2003

Duncan Mackenzie is the Visual Basic Content Strategist at msdn.microsoft.com
'Using' statement added to VB in Whidbey release... Posted: Jun 12, 2004 7:03 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Duncan Mackenzie.
Original Post: 'Using' statement added to VB in Whidbey release...
Feed Title: Code/Tea/Etc...
Feed URL: /msdnerror.htm?aspxerrorpath=/duncanma/rss.aspx
Feed Description: Duncan is the Visual Basic Content Strategist at MSDN, the editor of the Visual Basic Developer Center (http://msdn.microsoft.com/vbasic), and the author of the "Coding 4 Fun" column on MSDN (http://msdn.microsoft.com/vbasic/using/columns/code4fun/default.aspx). While typically Visual Basic focused, his blogs sometimes wanders off of the technical path and into various musing of his troubled mind.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Duncan Mackenzie
Latest Posts From Code/Tea/Etc...

Advertisement
Scott Watermasysk blogs about the new 'Using' statement in VB.NET 2005...
Using in VB.NET

I 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.

In VB.NET 2003 or 2002, you can get the same effect with this style of code
        Dim sw as New StreamWriter("C:\hey.txt")
        Try
            sw.Write("HEY")
        Finally
            sw.Dispose()
        End Try


Read: 'Using' statement added to VB in Whidbey release...

Topic: Indigo misperceptions Previous Topic   Next Topic Topic: [New blog] He Who Can Not Be Googled

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use