以下C#代码如何翻译为VB.NET?
var theVar = new List<string>{"one", "two", "three"};
以下C#代码如何翻译为VB.NET?
var theVar = new List<string>{"one", "two", "three"};
集合初始化器只在VB.NET 2010中可用,发布日期为2010-04-12:(参考链接)
Dim theVar = New List(Of String) From { "one", "two", "three" }
使用以下语法以实现 VB.NET 2005/2008 的兼容性:
Dim theVar As New List(Of String)(New String() {"one", "two", "three"})
虽然VB.NET 2010语法更好看。
Dim theVar As New List....
,否则theVar
将被视为一个Object
,智能感知将无法提供方法/属性等,您将收到编译器警告(尽管它仍然会编译)。 - freefallerOption Infer
,您就不需要这样做。 - SLaks