A Guide To VB 2008: Table 1: Quick Guide to VB 2008.

Visual Basic 2008 includes a host of significant new features, many of which <i>VSM</i> has already covered in the months preceding the official release. This handy reference details some of the more significant features, and provides some information on where you can learn more about them in cases where <i>VSM</i> has covered the topic already.

Feature What It Does
XML Support Provides native support for XML literals and XML expressions. See this article for more details.
Coalesce Operator The Coalesce operator takes two arguments. If the first is null, then the second argument is returned, otherwise the first argument is returned. Its syntax looks like this:
value = If(nullable, defaultValueIfNull)
For more details, see "Load Up with VB's Operators," August 2007
Ternary Operator A ternary operator is an inline If operator, as in this example:
value = If(BooleanExpression, ValueIfTrue, ValueIfFalse)
For more details, see "Load Up With VB's Operators," August 2007
Nullable Types Nullable types can be specified by using a ? modifier:
Dim x As Integer?   'same as Nullable(Of Integer)
VB 2008 also includes support for operators on nullable types. For more details, see the sidebar, "6 Tips for Nullable Types," in the On VB column, "Drill Down on Anonymous Types," October 2007
Type Inference Allows the variable's type to be inferred by the value assigned to it. The declaration (variable defined with the Dim keyword) must be accompanied with an assignment statement ( = statement). You can turn type inference on/off with the Option Infer statement. The syntax looks like this:
Dim name = "Bill"
For more details, see the question about inferred typing in Ask Kathleen
Object Initializers Use the With statement to set properties on an object as part of a constructor statement:
Dim cust as New Customer() With {.Name = "Bill"}
For more details, see the On VB column, "Drill Down on Anonymous Types," October 2007
Anonymous Types A type definition is created for you with properties with their types determined by the values you assign. VB has both mutable and immutable anonymous types: an immutable property is declared with the Key keyword:
Dim product = New () With {.Price = 9.99, Key .Name = "widget"}
For more details, see the On VB column, "Drill Down on Anonymous Types," October 2007
Extension Methods You apply the Extension attribute to methods declared in a module. These methods can then be used as if they are members of the first parameter's type. LINQ libraries contain extension methods on IEnumerable and IQueriable. For more details, see the On VB column, "Beautify Your Code with Extensions," May 2007
LINQ Language Integrated Query lets you use a SQL-like syntax in VB: im bills = From c in Customers Where c.FirstName = "Bill" For more details, see the On VB column, "LINQ Changes How You Will Program," September 2007
Lambda expressions Lambda expressions are inline functions. These are currently limited to a single statement. For more details, see the On VB column, "LINQ Changes How You Will Program," September 2007
Expression Trees Statements are compiled as expression trees, allowing interpretation and translation of the expression. A typical usage is an expression in a LINQ query is compiled to an expression tree, then at runtime translated to TSQL. For more details, see the On VB column, "LINQ Changes How You Will Program," September 2007
Partial methods Partial methods are designed for code generation. An empty Private method declaration (Sub) is included in the generated file and marked as Partial. You can then implement your own method with the same name, thus plugging into the generated code.
Relaxed Delegates You can use method signatures for event handlers where the parameter types are wider than the event specifies. This is most useful when you want to use the one handler for many different kinds of events in a Windows.Forms application. You can also omit all the parameters for the handler.
Friend Assemblies Include the InternalsVisibileTo attribute in an assembly to let another assembly access Friend scoped members. <Assembly: InternalsVisibleTo("FriendAssembliesB")>
comments powered by Disqus

Featured

Subscribe on YouTube