VB.NET中的内联列表初始化

时间:2010-04-13 11:27:14

标签: .net vb.net

  

可能重复:
  Collection initialization syntax in Visual Basic 2008?

以下C#代码如何转换为VB.NET?

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

2 个答案:

答案 0 :(得分:212)

集合初始值设定项为only available in VB.NET 2010,发布于2010-04-12:

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

答案 1 :(得分:159)

将此语法用于VB.NET 2005/2008兼容性:

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

虽然VB.NET 2010 syntax更漂亮。