在VB.Net创建时将项目添加到列表中 [英] Adding items to the List at creation time in VB.Net
本文介绍了在VB.Net创建时将项目添加到列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在c#中,我可以像创建时一样在创建时初始化一个列表
In c# I can initialize a List at creation time like
var list = new List<String>() {"string1", "string2"};
VB.Net中有类似的东西吗? 目前我可以做到
is there a similar thing in VB.Net? Currently I can do it like
Dim list As New List(Of String)
list.Add("string1")
list.Add("string2")
list.Add("string3")
但我想避免无聊.添加行
but I want to avoid boring .Add lines
推荐答案
VB10 supports collection initializers. I believe your example would be:
Dim list As New List(Of String) From { "string1", "string2", "string3" }
这篇关于在VB.Net创建时将项目添加到列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文