C# 到 VB.net List的转换有错误
我正在尝试将一些 C# 代码转换为 VB,但出现错误。正确的 VB 语法是什么?
C#
return new List<string> {"First Name", "Last Name", "First & Last Name", "None"};
VB
Return New List(Of String)() From {"First Name", "Last Name", "First & Last Name", "None"}
我也可以转换它怎么样? 暗淡列表作为新列表(国家/地区)()来自{新国家/地区()与{Key .Name =“选择国家/地区”,Key .Code =“0”}}
谢谢
I'm trying to convert some C# code to VB but I’m getting an error. What would be the correct VB syntax?
C#
return new List<string> {"First Name", "Last Name", "First & Last Name", "None"};
VB
Return New List(Of String)() From {"First Name", "Last Name", "First & Last Name", "None"}
And how about would I convert this too?
Dim list As New List(Of Country)() From { New Country() With { Key .Name = "Select Country", Key .Code = "0" } }
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VB10(Visual Studio 2010 的一部分)支持集合初始化,但 VB9 (VS 2008) 不支持。您发布的语法对于 VB10 是正确的。
在VB9中,您只需要以老式的方式处理它
VB9确实支持数组初始化
但是,数组的功能不如
List(of T)
,但如果您不需要添加或者删除元素,您当然可以使用数组而不是列表。Collection initialization is supported in VB10 (part of Visual Studio 2010), but not in VB9 (VS 2008). The syntax you posted is correct for VB10.
In VB9, you would just need to handle it the old fashioned way
VB9 does support array initialization
However, the array is not as functional as the
List(of T)
, but if you do not need to add or remove elements, you can certainly use an array instead of the list.