我想要做的是说我有一个列表列表的列表......
list1 = "A", "B", "C"
list2 = "1", "2", "3"
list3 = "Dog"
...
然后我得到一个带
的列表 newList = "A1Dog", "A2Dog", "A3Dog", "B1Dog", "B2Dog", "B3Dog", "C1Dog",
"C2Dog", "C3Dog"
有没有办法用LINQ做这个或者有更好的方法吗?
答案 0 :(得分:2)
是的,您可以简单地使用多个from
子句:
var result =
from x in list1
from y in list2
from z in list3
select x+y+z;
在csharp
交互式shell中,这给出了:
csharp> var list1 = new string[] {"A", "B", "C"};
csharp> var list2 = new string[] {"1", "2", "3"};
csharp> var list3 = new string[] {"Dog"};
csharp> var result =
> from x in list1
> from y in list2
> from z in list3
> select x+y+z;
csharp> result
{ "A1Dog", "A2Dog", "A3Dog", "B1Dog", "B2Dog", "B3Dog", "C1Dog", "C2Dog", "C3Dog" }