Inline list initialization in VB.NET

.Netvb.net

.Net Problem Overview


> Possible Duplicate:
> Collection initialization syntax in Visual Basic 2008?

How is the following C# code translated to VB.NET?

var theVar = new List<string>{"one", "two", "three"};

.Net Solutions


Solution 1 - .Net

Collection initializers are only available in VB.NET 2010, released 2010-04-12:

Dim theVar = New List(Of String) From { "one", "two", "three" }

Solution 2 - .Net

Use this syntax for VB.NET 2005/2008 compatibility:

Dim theVar As New List(Of String)(New String() {"one", "two", "three"})

Although the VB.NET 2010 syntax is prettier.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBoris CallensView Question on Stackoverflow
Solution 1 - .NetSLaksView Answer on Stackoverflow
Solution 2 - .NetPrutswonderView Answer on Stackoverflow