0

I need to join these three 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"}

To get output like this List(Of String):

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

What is most effictive way? LINQ way? Thanks!

AsValeO
  • 2,859
  • 3
  • 27
  • 64
  • 2
    Sorry, can't remember the VB syntax at the moment, but I believe this should work: `lst1.SelectMany(m => lst2.SelectMany(c => lst.Select(a => m + c + a)))` – Asad Saeeduddin Dec 16 '14 at 18:11
  • It works, thanks! Post the answer and I'll accept it! VB.NET version: `Dim result = lst1.SelectMany(Function(m) lst2.SelectMany(Function(c) lst3.[Select](Function(a) m + c + a))).ToList` – AsValeO Dec 16 '14 at 18:15
  • 1
    @Asad `lst1.SelectMany(function(l) lst2.SelectMany(function(ls) lst3.Select(function(lst) string.format("{0}{1}{2}",l,ls,lst))))` – asawyer Dec 16 '14 at 18:16
  • @ValeO Since you've got the exact answer figured out, you can post this as an answer to your own question (which is encouraged). – Asad Saeeduddin Dec 16 '14 at 18:17
  • @asawyer, your variant works well too, thanks! – AsValeO Dec 16 '14 at 18:21

1 Answers1

1

Both of these variants works:

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))))
AsValeO
  • 2,859
  • 3
  • 27
  • 64