Close this search box.

New Features in VB.NET 10 (.NET 4.0)

Following the PDC, there has been a whole host of announcements about the new features we’ll be seeing in .NET 4.0. I’d like to take a moment to look at some of the features that will be coming to VB.NET 10.

Auto implemented properties
When this feature came to C# it created real language envy among VB developers. In those instances where all you need a property to do is hold a value (i.e. where a public field would do the job nicely if it wasn’t evil), C# 3.0 allows the developer to write the property using a shorthand notation and the compiler will implement the private field for you:

public int CustomerID
   get   { return customerIdField; }
   set   { customerIdField = value; }

Can be written as:

public int CustomerID { get;  set; }

Of course, if you need to access the private field you need to write the property using the first style, but if you don’t the shorthand is really useful. VB.NET is getting this feature using the following syntax:

Public Property CustomerID As Integer

Collection Initialisers
Another feature C# has that is missing from VB.NET is the ability to declare and initialise a collection in one go. Well, the playing field is getting levelled a little more in .NET 4.0 as this feature is added to VB:

Dim words As New List(Of String) From {"Hello", "World"}

Implicit Line Continuations
In C# a statement is finished with a semicolon, so you can add new lines wherever you want to improve readability. Not so in VB.NET, if you want a new line you need to let the compiler know it’s not the end of the statement by adding an underscore (the line continuation character). With VB 10 the compiler will be smart enough to infer the line continuation character in most cases:

Dim s As String = “Hello” &

Of course, it is likely to be confused if the line is a valid statement:

Dim s As String = "Hello"
  & "World"

In those cases you’ll still need the underscore.

I’ve just touched the surface of some of the new features we should be seeing in VB.NET 10, but it is already looking very exciting! I’m sure I’ll be blogging about many more features as the details are released…

This article is part of the GWB Archives. Original Author: Darren Fieldhouse

Related Posts