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

Following the , 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” &
 “World”

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: gwbarchive

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.