Their are a number of new features for the next version of VB.Net. I’m guessing that next version will be called VB11 but it could be VB10.5, who knows.
The least you can say is that the number of new features is not that impressive. According to the official MSDN website
- Async Feature
- Call Hierarchy
- Global Keyword in Namespace Statements
Async/Await has been around in the form of a CTP for a while, it was a separate project up till now. I think this might be big but I’m sure that people who don’t understand multithreading won’t understand this either. Since you can use it with the .Net framework 4 I would not call this a “new” feature of .net framework 4.5.
I have blogged about Async before.
Call Hierarchy enables you to navigate through your code by displaying the following:
All calls to and from a selected method, property, or constructor.
All implementations of an interface member.
All overrides of a virtual or abstract member.
Why am I not that overwhelmed by this new feature? I already had all this and more with Resharper. Let’s move on nothing to see here, not for me anyway.
The namespace thing
I blogged about this a short while ago. “In VB11 the namespace difference between VB and C# will be … smaller.“. This one solves a problem that never really bothered me. But I guess some people will use this a couple of times a year.
Now this is a feature I have been waiting for. Finally something I think is really new and useful. I wanted more of this. That’s also why I kept it for last.
Now what is it. In essence they added the yield keyword to VB.Net. The yield keyword has been around in C# since VS2005.
You can see what it does on the MSDN page.
And if you switch between the C# code and the VB.Net code you will see something odd.
I’ll show the relevant lines below.
public static System.Collections.IEnumerable SomeNumbers()
Private Iterator Function SomeNumbers() As System.Collections.IEnumerable
Never mind the difference in public and private or static and no shared keyword because you are in a module things.
It’s the Iterator keyword you need in VB.Net to get the yield to work. So when you use the yield keyword in a method you have to make that method an Iterator. Probably not the most elegant way of doing things but not to bad either.
And you will want to pay special attention to this section.
Anonymous Methods in Visual Basic
In Visual Basic (but not in C#), an anonymous function can be an iterator function. The following example illustrates this.
Dim iterateSequence = Iterator Function() _
As IEnumerable(Of Integer)
As we all know the “but not in C#” bit, can come back and bite you in the future. not sure what will happen if you pass that function to a C# lib. I might need to try that. It might just work.
There is only one feature in that list that seems to be worth the upgrade. The biggest question of course is if they have succeeded in solving some of the incompatibilities with C#. I will write about that later.