在VB.NET中加入多个List(Of String)

时间:2014-12-16 18:05:40

标签: vb.net string linq list join

我需要加入这三个List(Of String)

Dim lst1 As New List(Of String) From {"man1"}
Dim lst2 As New List(Of String) From {"/1child", "/2child"}
Dim lst3 As New List(Of String) From {"/1age", "/2age"}

获取此List(Of String)的输出:

man1/1child/1age
man1/1child/2age
man1/2child/1age
man1/2child/2age

最有效的方法是什么? LINQ方式?谢谢!

1 个答案:

答案 0 :(得分:1)

这两种变体都有效:

Dim result = lst1.SelectMany(Function(m) lst2.SelectMany( _ 
Function(c) lst3.[Select](Function(a) m + c + a))).ToList

Dim result2 = lst1.SelectMany(Function(l) lst2.SelectMany( _ 
Function(ls) lst3.Select(Function(lst) String.Format("{0}{1}{2}", l, ls, lst))))