Why do array initializers only allow arrays?

Possible duplicate:
Collection initialization syntax in Visual Basic 2008?

This does not compile.

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

It does

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

IMO, these functions should be allowed for all types of collections, not just arrays.

+5
source share
2 answers

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

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

It uses the new of the keyword .

#, , Visual Studio 2008. ( # ) (MSDN).

+4

Microsoft . VB, VB 2010. . : VB 2008?.

MSDN: Visual Basic 2010?

+3

All Articles