Hidden Gems in Visual Basic 2008 by Amanda Silver

I found that one at the Visual Basic Team Blog. Over here she puts together a list of some of the new features in Visual Basic 2008:

I like these 🙂
2) If Operator

Ever notice that the IIF function returns something of type Object? This means that you don’t get Intellisense or type-checking by default on that result. For those of you that insist on type-safe, early-bound code, you have to cast the result. The code then looks something like this:

With the If operator, you can now write that line as:

And with type inference it gets even easier on the eyes:

clip image004 thumb Hidden Gems in Visual Basic 2008 by Amanda Silver

4) Nullable

Nullable is the feature you’ll notice but rarely have to think about. It’s basically the .NET representation for a Nullable value type (Integer, Date, etc.) Using the designer for LINQ to SQL, the Object-Relational Mapping layer introduced in Visual Studio 2008, nullable columns in your database are mapped to this type. The result is that you can write the following expression in VB and the right thing happens – null valued rows propagate null. In the example below, the Independence property on the Country type is a nullable date, denoted as Date?

9) Type inference for loop variables

Check out the following code:

clip image020 thumb Hidden Gems in Visual Basic 2008 by Amanda Silver

And this code:

clip image022 thumb Hidden Gems in Visual Basic 2008 by Amanda Silver

Without having to specify the type of the control variable, it’s inferred from right-hand-side expression or the collection we’re iterating over.

read all of them from here


Leave a Reply

Your email address will not be published. Required fields are marked *