Thursday, January 26, 2006

 

VB.NET 2005 - Continue & Using keywords

Continue
This is one of the features I've been looking for in VB .NET and I'm glad they added this functionality. Using this keyword insie the loop allows you to skip and perform the next iteraion. Continue For is used cojunction with For loop and Continue While is use in while loop.

Using
This is for garbage collection where in developer wishes to explicitly clean up the unmanged resources before abandoning an object. The object must implment IDisposable. Please see below for an example:

Public Class Countries
Inherits Generic.List(Of Country)
Implements IDisposable

Public Overloads Sub Add(ByVal CountryName As String)
Dim itm As New Country
itm.CountryName = CountryName
Me.Add(itm)
Dim i As Integer = Me.Count - 1
Me.Item(i).IDCountry = Me.Count
End Sub

Public Overloads Sub Dispose() Implements IDisposable.Dispose
' Do some clean up here
End Sub
End Class




To explicity clean up the unmanged resources
Dim mCountries As New Countries
' Retrive some data from mCountries
Using (mCountries)
' Manipulate data
End Using







This page is powered by Blogger. Isn't yours?