Due to the popularity of some sessions, I decided to do a hands-on lab instead of following a session in an overcrowded room. Due to my love for Visual Basic (hey, just shoot me :)), I chose to do the lab on new features of VB.NET in Whidbey. Here's an overview of what I think to be exciting new features:
Generics
Yes, VB.NET will support generics.
Dim myProducts As New List(Of Products)
The previous line will create a list collection of objects of the Products type.
Operator overloading
Yes, you will be able to overload operators. This enables you to specify how the compiler should treat operators, such a plus, minus, ..., for your own type.
Shared Operator +(ByVal person1 As Person, ByVal person2 As Person2) As Couple
This will allow you to specify what must happen when 2 Person objects are added. In the previous example it will return a Couple object.
I know, I know, C# had this already since v1.0, but hey, it's coming to VB.NET too...
The "My" object
The "My" object lets a developer do things he might need to do regularly, like:
- Retrieving information about the logged on user (domain, user name, Windows roles)
- Retrieving application information (description, file name, name of the special folder for storing user & application bound data)
- Retrieving information about the computer
- Event logs
- Keyboard information (is caps or num lock pressed)
- Mouse information (is it a wheel mouse, how many buttons are on the mouse)
- Screen information (resolution, boundaries)
- Network information (connected, IP address)
- Accessing the registery
- Accessing printer information
Well, as you can imagine, quite a full set of things a developer might want to access.
XML Comments
After typing '@ the editor will automatically generate an XML comments template with all parameters defined for the method.
Unsigned types
Visual Basic .NET is going to support unsigned types. You know, a "word" for example is an unsigned integer: in VB.NET is will become a UInteger if I recall it correctly. This allows developers to save memory in some cases. Example: you want to store a number between 0 and 40,000. Currently you have to use a Long for that which takes 8 bytes. By using an unsigned integer you will be able to store this value in 2 bytes.
IDE tools to create data driven forms
I actually created an application with one form displaying categories of products and in detail the products themselves. In addition filtering of the detail data was also provided (on stock or unavailable). All with no code at all.
Smart tags
Smart tags (and not Smart Tasks like I wrote earlier) for great help in doing some common layouting stuff. For example changing a DataContainer control from displaying a grid into individual fields for a record can be done just by clicking.
Autocorrecting mistakes
Visual Basic .NET will actively help you correcting (stupid) mistakes. Suppose you defined a read-only property, but created a Get and Set method in the property. Visual Basic .NET will at design-time tell you there is something wrong, just as it did before. But now, VB.NET helps you by identifying 2 solutions: the first one is removing the "Readonly" from the property, the second one is removing the "Set" method. You just pick the solution you want and VB applies it. And oh yes, this feature has to be triggered manually by using a smart tag on the squizzles (blue line) that appear under the error line.
Edit and continue
Well, it actually works on the PDC bits of Whidbey. Believe me, I tried it. However, I did not push it to the limits. And you can also reposition the line that will be executed by dragging the yellow arrow.
Partial types
You do not longer need to create a type (class) in one file. From Whidbey on, you can create one part of the type in one file and another one in another file. This is especially great if you have several developers working on one type. I know I could have used this in more than one project I worked on.
Code snippets
For many common tasks, Whidbey provides code snippets. Many applications need to save some content to a file in the My Documents folder. Instead of coding this every time again or copy-pasting it from a library, just use the code snippets (right click in the code and go the code snippets popup menu). Code snippets can contain template fields. These template fields are used for data that must probably be changed (in our example this would be the file name and the actual content that you will save). You can switch between these template fields by using the Tab key.
Best of all, a developer can create his own code snippets and define his own template fields in every snippet.
I'm not sure where the snippets are stored and if they can be shared amongst several developers (in a database, for example).
Isn't this great?