New VB.NET Syntax since VS2005

I have not used VB.NET seriously after VS2003. Recently, I had to maintain an old VB.NET application so I had to spend a bit time to find out the VB equivalent of new C# syntax introduced in VS2005 or later:

Category C# VB.NET
Generics List<string> List(Of String)
Object Initializer new Person() { First=”a”, Last=”b” } New Person() With {.First = “a”, .Last = “b” }
Anonymous Type var a = new { First=”a”, Last=”b” }; Dim a= New With {.First = “a”, .Last = “b” }
Array or Collection Initializer int[] a = {0, 2, 4, 6, 8};
or
int[] a = new int[] {0, 2, 4, 6, 8};
Dim a() as Integer = {0, 2, 4, 6, 8}
or
Dim a() as Integer = New Integer()  {0, 2, 4, 6, 8}
Dictionary Initializer Dictionary<int, string> d = {{1, "One"}, {2, "Two"}}; Dim d As Dictionary(Of Integer, String) = {{1, "One"}, {2, "Two"}}
Lambda Expression x => x * x function(x) x*x
Multiline Lambda Expression (input parameters) => {statements;} function(input parameters) 
    statements
end function

No Comments