What's new in June Orcas CTP for VB

Posted Mon, Jul 9 2007 14:25 by bill

Many of the little features are in VB Orcas as of June (no need to wait till Beta 2)

 

(1)  Lambda functions are in.

Dim f = Function(x As Int32) x + 1
Dim y = f(2)
' y now equals 3

 

(2)  nullable type support

This includes declaration of nullable types with ?, and operators elevation from the non nullable type with null propagation.

Dim i? as Int32     ' i is as Nullable(of Int32)
Dim j as Int32?    ' j is also a Nullable(Of Int32)

Dim k = i + j    ' k is inferred to be Nullable(Of Int32)

Note how you can use the + operator on the Nullable(Of Int32)'s.  If either i or j is null, then k will be null.

 

(3) new If operations

Dim name as String = If(customer IsNot Nothing, customer.Name, "")

The If function replaces the IIf function except unlike IIf, If(,,) only evaluations the parts used.  Given the above example, if customer was null, the customer.Name expression would cause a null reference exception when using IIf because it is a function and all parameters need to be evaluated. If(,,) is actually a ternary operator so only the parts needed are evaluated, which in this case avoids the null reference exception.

 

A second If operator is also available: If(,).  This operator only takes two operands and is designed for work with nullable types.

Dim i as Integer?
Dim n As Integer = If(i, 0)

Basically this translates to If i is not null then return i's value, otherwise return the second operand value 0

 

(4) LINQ

 

LINQ seems to be in full force as of Orcas.  I haven't fully tested it yet but so far everything works.  Note some things are different in VB compared to C#, for example see my previous post on Group By in VB. In C# Groupy By returns an IGrouping(key, IEnumerable(data)), whereas VB returns an IEnumerable(key, IEnumerable(data)).

Filed under: , ,

Comments

# re: What's new in June Orcas CTP for VB

Monday, July 09, 2007 4:24 PM by Roger Jennings

There's more info on VB 9.0 lambda functions in LINQ method call syntax and a link to this post here: oakleafblog.blogspot.com/.../orcas-and-entity-framework-june-2007.html

--rj