VB.NET 中的内联列表初始化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2629076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inline list initialization in VB.NET
提问by Boris Callens
Possible Duplicate:
Collection initialization syntax in Visual Basic 2008?
How is the following C# code translated to VB.NET?
以下 C# 代码如何转换为 VB.NET?
var theVar = new List<string>{"one", "two", "three"};
回答by SLaks
Collection initializers are only available in VB.NET 2010, released 2010-04-12:
集合初始值设定项仅在 VB.NET 2010 中可用,发布于 2010-04-12:
Dim theVar = New List(Of String) From { "one", "two", "three" }
回答by Prutswonder
Use this syntax for VB.NET2005/2008 compatibility:
使用以下语法实现VB.NET2005/2008 兼容性:
Dim theVar As New List(Of String)(New String() {"one", "two", "three"})
Although the VB.NET 2010 syntaxis prettier.
尽管VB.NET 2010 语法更漂亮。

