views:

104

answers:

2

This does not compile.

Dim Tom As New List(Of String) = {"Tom", "Tom2"}

This does

Dim Tom As String() = {"Tom", "Tom2"}

IMO this features should be allowed for all collection types and not only arrays.

+3  A: 

Microsoft agrees with you. It is supported starting in the next release of VB, VB 2010. See this question: Collection initialization syntax in VB 2008?.

MSDN: What's New in Visual Basic 2010?

magnifico
+3  A: 

You cannot do this in the current version of Visual Basic, but the next version in Visual Studio 2010 allows this syntax:

Dim Tom As List(Of String) = new List(Of String) From {"Tom", "Tom2"}

It uses the new From keyword.

Edited to Add:

C# has included its Collection Initializer syntax Visual Studio 2008. You can read about it on MSDN.

Nick
re your edit: C# already supports collection initializer syntax.
Jimmy
@Jimmy - Thanks for pointing that out.
Nick