62,243
社区成员




List<string> A = new List<string> { "S1", "S2", "S3" };
List<string> B = new List<string> { "B2" };
List<string> C = new List<string> { "C1", "C2" };
List<List<string>> list = new List<List<string>>()
{
A,
B,
C
};
var result = list.Aggregate((thisCurrent, nextCurrent) => thisCurrent.SelectMany(x => nextCurrent.Select(y => y + x)).ToList());
foreach (var temp in result)
{
Response.Write(temp + "<br/>");
}
List<string> RecursionLINQ(List<string[]> list, int startCount, List<string> result)
{
if (startCount < list.Count)
{
result = result.Count == 0 ?
(from b in list[startCount] select b).ToList() :
(from a in result from b in list[startCount] select a + b).ToList();
result = RecursionLINQ(list, startCount + 1, result);
}
return result;
}
string[] strs1 = { "S1", "S2", "S3" };
string[] strs2 = { "B2" };
string[] strs3 = { "C1", "C2" };
List<string[]> list = new List<string[]>();
list.Add(strs1);
list.Add(strs2);
list.Add(strs3);
List<string> result = new List<string>();
result = RecursionLINQ(list, 0, result);