# Wednesday, May 19, 2004

We all know and love the C# version of foreach where you specify the type in the loop like this

foreach ( object o in list )

In VB.NET 1.0 you had to do declare the variable outside of the loop which is pretty ugly as you might end up using it later in your code by accident. With VB.NET 1.1 you can do a foreach loop the C# way which probably is the new feature of .NET Framework 1.1 I use the most :)

So in the old way you would do this:

Dim o As Object
For Each
o In list
Next

The new way allows you to use this form instead:

For Each o As Object In list
Next

Most people probably know this but I think it's worth mentioning for the 5 people who haven't discovered it yet.

Comments are closed.