VB Net - 如何将元组添加到列表中

时间:2014-06-30 13:53:22

标签: vb.net list tuples

我一直在寻找一天来搜索这个主题 例如:

#I don't know how to create it to the script so I describe it like this

list  = {("Cat", "Dog", "Cow"), ("Milk", "Egg", "Pizza")}

list(0)
#("Cat", "Dog", "Cow")
list(0)(0)
#Cat
list(0)(1)
#Dog
list(1)(1)
#Egg

任何人都知道如何在vb net上做到这一点

1 个答案:

答案 0 :(得分:1)

您正在寻找类似的东西:

Dim list = new List(Of String()) From 
{ 
    new String(){"Cat", "Dog", "Cow"}, 
    new String(){"Milk", "Egg", "Pizza"} 
}

Dim list = new List(Of String())
list.Add({"Cat", "Dog", "Cow"})
list.Add({"Milk", "Egg", "Pizza"})

现在你可以使用:

' prints Cat, Dog, Cow
Console.WriteLine(String.Join(", ", list(0)))
' prints Cat
Console.WriteLine(list(0)(0))
' prints Dog
Console.WriteLine(list(0)(1))
' prints Egg
Console.WriteLine(list(1)(1))