110,533
社区成员
发帖
与我相关
我的任务
分享
string[] level1 = { "S1", "S2", "S3" };
string[] level2 = { "B2" };
string[] level3 = { "C1", "C2" };
List<string> result = new List<string>();
for(int i = 0;i< level1.Length;i++ )
{
for(int j = 0;j < level2.Length; j++)
{
for (int k = 0; k < level3.Length; k++)
{
result.Add(string.Format("{0},{1},{2}", level1[i], level2[j], level3[k]));
}
}
}
var arrays = new[]
{
new[]{"S1","S2","S3"},
new[]{"B2"},
new[]{"C1","C2"},
};
IEnumerable<string> result = new[]{""};
result = arrays.Aggregate(result, (current, array) => current.SelectMany(y => array.Select(z => y + z)));
void function(string[ ] s,int step,int maxStep)
{
for(int i=0;i<数组[step].Length;i++)
{
if(step==maxStep)
{
s[step]=数组[step][i];
//输出或保存s
}
else
{
function(s,step+1,maxStep);
}
}
}
调用的时候,执行
function(new string[数组长度],0,数组长度);