Two New Features in Visual Basic 2008 and Express

Old and possible Obsolete Article

Visual Basic 2008 does have quite a few features over 05. A lot of these features are added to the 3.0-3.5 version of the Dot Net Framework. VB 08 includes design support for WPF (Windows Presentation Foundation, WWF (Windows Workflow Foundation; It used to be called WinFX), ), WCF(Windows Communication Foundation), etc. You can click here to get a overview of WWF. IF you want to get started with WPF, you can click here. IF interested in WCF, then check it out here.

Another big feature for VB 08 is LINQ(Language Integrated Query). LINQ adds query capabilities for collections, SQL databases, ADO.NET Datasets, and XML documents. IF you do want to get started with LINQ, you can go to this MSDN Link and get going.

But I was more interested in taking a look at the somewhat ‘lesser’ hyped features for VB 9.0. I will try to put down some of the stuff I read at msdn. Its quite possible I may not add anything more useful than you already know 🙂 And I hope I do not explain something with the wrong answer 🙂 Feel free to leave a comment to let me know…

Local Type Inference

This little feature now makes it possible that you do not have to specify the actual type for local variables. It will set the type on its own depending on what value it ends up containing…

'This is the normal, traditional way of declaring variables...

Dim testWithType As Integer = 100


Dim testWithType As Integer

testWithType = 100

Now setup a new variable with Local Type Inference…

Dim testNoType

testNoType = 100


Dim testNoType = 100

'You can check which type was assigned to the variable with the code below if you want...


Based on the value of 100 that was set to it, it ends up being a Integer and the Msgbox message should display the type as ‘Integer’. P

Pretty nifty feature? The less code you have to write the better?

Object Initializers

Object initializers enable you to initialize a complex object and specify its properties by using one expression. In other words, when you declare a new object, you can use the With statement after the object you are wanting and add brackets after the With statement {  }. Inside the brackets you can automatically set properties related to that object.

Say you wanted to create a new Form, and want the .Backcolor a certain color and the MaximizeBox property set to False. You can automatically set these properties inside the Initializer Brackets. A example code for performing this is below…

See the Object Initializers in use…

Dim frm As New Form With {
    .BackColor = Color.Aqua,
    .MaximizeBox = False,
    .ForeColor = Color.Blue,
    .Owner = Me}

Pretty spiffy huh?

Well, those are two features I will use and wanted to outline them here. I may add another article with some of the other new features like Anonymous Types, Extension Methods, ect… But I do not feel like it now. Anyways, hope this small article was worth the read…


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.