jump to navigation

VB 10.0 new features and Visual Studio 2010 IDE enhancements June 27, 2009

Posted by fofo in Visual Basic 10.0.
Tags: ,

I have downloaded the .Net 4.0 version of the framework and VS 2010 beta version 1 from the microsoft site and I started looking at the new features, IDE e.t.c. Visual studio 2010 has some exciting features.

In this post I will try with a step by step example to highlight the new features of VB 10.0. I will also highlight some of the new enhancements on VS 2010 IDE. There are many new things in .net 4.0 and VS 2010 and certainly I will not cover everything in this post.

The first thing we must do is to create a sample application. I will create a console application. So just fire VS 2010 and from the available templates select a Console application.

Consume first mode

There is a new enhancement in the IntelliSense functionality. We have two alternatives for IntelliSense statement completion: standard mode and consume-first mode. This basically means that we consume classes,types,methods before we actually define them. Have a look at the picture below. In the Main() method I start to use this method without even declaring it first.

Sub Main()

addtwonums(3, 5)

End Sub


When I type the new method I receive a curly line from the compiler and I can realise that there is not a method with such a name.

If I hit CTRL + . a simple method structure is created for me.

Private Sub addtwonums(ByVal p1 As Integer, ByVal p2 As Integer)
Throw New NotImplementedException
End Sub

Now I can go on and finish my method.

This works equally well with classes I have not implemented yet. I have the declaration below in my Main() method.

Dim myperson As New Person

With the same mechanism, CTRL+. we can have a new Person.vb file created in the Solutions window.

Auto-Implemented Properties

Auto-implemented properties, which is a feature that was available with C# 3.0, provides us with a way to specify a property of a class without having to write code to Get and Set the property.If I start setting values to the myperson object, like the code below

Dim myperson As New Person

myperson.name = “Michael”
myperson.surname = “Owen”


I can create properties (without Get and Set)for the name,surname and a method stub for the Walk() method.So in my Person.vb file I have:

Class Person

Property name As String
Property surname As String
Sub Walk()
Throw New NotImplementedException
End Sub
End Class

Also note that you can With auto-implemented properties, a property, including a default value, can be declared in a single line. For example

Public Property Name As String = “John”

It is great seeing that Microsoft has decided to bring VB to the same level as C#. For the future of VB you can listen to this fantastic podcast where Joe Stagner talks with Lisa Feigenbaum from the .NET Managed Languages Group. Another great thing is that Αnders Hejlsberg is going to be in charge of the VB language as well. We know Anders is probably the most suitable person for driving VB to the future.

Collection Initialisers

Collection initialisers was a feature of C# 3.0 and basically it is a new syntax we can create a collection and populate it with an initial set of values. Let’s create a collection of List(Person). Each value that is supplied in the collection initializer is passed to the appropriate Add method of the collection.Inside my Main() method I can create

Dim people As New List(Of Person) From {
{New Person With {.name = “michael”, .surname = “owen”}},
{New Person With {.name = “kenny”, .surname = “daglish”}},
{New Person With {.name = “robbie”, .surname = “fowler”}}}

Please note that there is no “_”, underscore anymore.For more information on this topic see this video and this site.

Multiline Lambdas

In order to demonstrate this, let’s add another console application to our solution. Until VB 9.0 we had only inline lambda expressions. In VB 10.0 we have multiline lambdas. Consider the code below, we just have an array of temperatures and we want to find values greater than 30 degrees.

Dim temperatures(4) As String

temperatures(0) = 12
temperatures(1) = 23
temperatures(2) = 34
temperatures(3) = 45

Dim heightemperatures = temperatures.Where(

Return (temperature > 30)

End Function).ToList()


End Sub)

As you can see in this line bit of the code,

Dim heightemperatures = temperatures.Where(Function(temperature)
Return (temperature > 30)

End Function).ToList()

I am using a multiline lambda expression where I pass into the temperature.

In this part of the code I just display the temperatures on the console by using  Lambda statements (a new feature in vb 10.0) by using the Sub keyword.


End Sub)

For our array declaration we could use .Instead of typing this

Dim temperatures(4) As String

temperatures(0) = 12
temperatures(1) = 23
temperatures(2) = 34
temperatures(3) = 45

we could type this equivalent chunk of code

Dim temperatures = {12, 23, 34, 45}

This is a another new feature called array literals.

Parallel Support

We can execute parts of our program asynchronously-not in sequence using the Parallel object of the.Net 4.0 framework.

The first thing is to import the relevant namespace at the beginning of our code.

Imports System.Threading

To give you a simple example , we can write the following bit of code to output two strings in parallel on the console.Place the code inside the Main () routine.

Console.WriteLine(“My name”)
End Sub,
Console.WriteLine(“My surname”)
End Sub

We use the Invoke method to execute the tasks in parallel.

Run the code and see that the two strings outputted  simultaneously on the screen.For more information on Parallel computing have a look here.

Call Hierarchies

This is a brand new feature of the IDE in VS 2010. If you select a method and right click on it and select View Call Hierarchy so we can see in a niew window that appears titled “Call Hierarchy” which method calls (Calls to) this particular method and what methods this method calls(Calls from). See the picture below.

call hierarchies

Quick Symbol Search

In the code editor if you type CTRL + , the Navigate To window appears. You can enter the name of the type,variable you want and it will find all instances and by clicking on them you will navigate easily to them. Have a look at the picture below.

quick search

Highlighting References

We can highlight all instances of a particular of property , method e.t.c by simply clicking on it.

We can navigate between instances with CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW.

Enhancements to ASP.NET Multi-Targeting

In Visual Studio 2008, when we targeted a project for an earlier version of the .NET Framework most features of the development environment adapted to the targeted version. However, IntelliSense displayed language features that are available in the current version, and property windows displayed properties available in the current version. In Visual Studio 2010 only language features and properties available in the targeted version of the .NET Framework are shown.

Code Editor

The new Code Editor makes code easier to read. You can zoom in on text by pressing CTRL and scrolling with the mouse wheel.

Visual Studio Debugger

There are Breakpoint enhancements in VS 2010 such as

  • Searching in the Breakpoints window
  • Label breakpoints
  • Import and export breakpoints
  • String comparison for breakpoint conditions in native debugging

See the picture below.



The Chart Control

This control sports various chart types, including point, column, bar, area, doughnut and many more.It can be rendered in a 3D mode. For more information click here and here .

Add to FacebookAdd to NewsvineAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to Ma.gnoliaAdd to TechnoratiAdd to Furl



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: