List<List<String>> list0 = new List<List<String>>()
{
new List<String>(){"0","2","3"},
new List<String>(){"1","7","4"},
new List<String>(){"2","9","4"},
};
List<List<int>> list_初始值 = new List<List<int>>()
{
new List<int>(){0,2,3},
new List<int>(){1,7,4},
new List<int>(){2,9,4},
};
List<List<String>> result = (from x in list_初始值[0]
from y in list_初始值[1]
from z in list_初始值[2]
select new List<string>() { x.ToString(), y.ToString(), z.ToString() }).ToList();
/// <summary>
/// 获取相应的笛卡尔乘积组合,输入的是对象集合所对应的Count集合
/// </summary>
/// <param name="iList">要生成的对象索引集合,如:{3,2,1,5}</param>
/// <returns>数组集合,每一个数组都对应一组索引集合</returns>
public static List<int[]> GetCrossJoin(this IList<int> iList)
{
List<int[]> rList = null;
int totalRows = 0;
if (iList != null && iList.Count > 0)
{
totalRows = 1;
foreach (int i in iList)
{
totalRows *= i;
}
}
if (totalRows != 0)
{
rList = new List<int[]>();
for (int i = 0; i < totalRows; i++)
{
rList.Add(new int[iList.Count]);
}
int repeatNum = totalRows;//该值表示批量内应该重复的次数
int repeatPa;//表示批量执行次数,每个重复应该出现多少次
int intervalNum;//表示每批重复应该有的间隔
for (int i = 0; i < iList.Count; i++)
{
repeatNum /= iList[i];
repeatPa = totalRows / repeatNum / iList[i];
intervalNum = repeatNum * iList[i];
for (int m = 0; m < repeatNum; m++)
{
for (int n = 0; n < repeatPa; n++)
{
for (int l = 0; l < iList[i]; l++)
{
rList[intervalNum * n + m + l * repeatNum][i] = l;
}
}
}
}
}
/// <summary>
/// 获取相应的笛卡尔乘积组合,输入的是对象集合所对应的Count集合
/// </summary>
/// <param name="iList">要生成的对象索引集合,如:{3,2,1,5}</param>
/// <returns>数组集合,每一个数组都对应一组索引集合</returns>
public static List<int[]> GetCrossJoin(this IList<int> iList)
{
List<int[]> rList = null;
int totalRows = 0;
if (iList != null && iList.Count > 0)
{
totalRows = 1;
foreach (int i in iList)
{
totalRows *= i;
}
}
if (totalRows != 0)
{
rList = new List<int[]>();
for (int i = 0; i < totalRows; i++)
{
rList.Add(new int[iList.Count]);
}
int repeatNum = totalRows;//该值表示批量内应该重复的次数
int repeatPa;//表示批量执行次数,每个重复应该出现多少次
int intervalNum;//表示每批重复应该有的间隔
for (int i = 0; i < iList.Count; i++)
{
repeatNum /= iList[i];
repeatPa = totalRows / repeatNum / iList[i];
intervalNum = repeatNum * iList[i];
for (int m = 0; m < repeatNum; m++)
{
for (int n = 0; n < repeatPa; n++)
{
for (int l = 0; l < iList[i]; l++)
{
rList[intervalNum * n + m + l * repeatNum][i] = l;
}
}
}
}
}
/// <summary>
/// 获取相应的笛卡尔乘积组合,输入的是对象集合所对应的Count集合
/// </summary>
/// <param name="iList">要生成的对象索引集合,如:{3,2,1,5}</param>
/// <returns>数组集合,每一个数组都对应一组索引集合</returns>
public static List<int[]> GetCrossJoin(this IList<int> iList)
{
List<int[]> rList = null;
int totalRows = 0;
if (iList != null && iList.Count > 0)
{
totalRows = 1;
foreach (int i in iList)
{
totalRows *= i;
}
}
if (totalRows != 0)
{
rList = new List<int[]>();
for (int i = 0; i < totalRows; i++)
{
rList.Add(new int[iList.Count]);
}
int repeatNum = totalRows;//该值表示批量内应该重复的次数
int repeatPa;//表示批量执行次数,每个重复应该出现多少次
int intervalNum;//表示每批重复应该有的间隔
for (int i = 0; i < iList.Count; i++)
{
repeatNum /= iList[i];
repeatPa = totalRows / repeatNum / iList[i];
intervalNum = repeatNum * iList[i];
for (int m = 0; m < repeatNum; m++)
{
for (int n = 0; n < repeatPa; n++)
{
for (int l = 0; l < iList[i]; l++)
{
rList[intervalNum * n + m + l * repeatNum][i] = l;
}
}
}
}
}
var array1 = list0.Aggregate((m, n) => m.SelectMany(t1 => n.Select(t2 => "\"" + t1 + "\",\"" + t2 + "\"").ToList()).ToList()).ToList();
List<String> list1 = new List<string>();
foreach (string a in array1)
{
list1.Add(a.ToString().Replace("\"\"", "\""));
}
List<List<String>> list01 = new List<List<String>>();
list01.Add(list1);
--------------------编程问答--------------------
/// <summary>
/// 获取相应的笛卡尔乘积组合,输入的是对象集合所对应的Count集合
/// </summary>
/// <param name="iList">要生成的对象索引集合,如:{3,2,1,5}</param>
/// <returns>数组集合,每一个数组都对应一组索引集合</returns>
public static List<int[]> GetCrossJoin(this IList<int> iList)
{
List<int[]> rList = null;
int totalRows = 0;
if (iList != null && iList.Count > 0)
{
totalRows = 1;
foreach (int i in iList)
{
totalRows *= i;
}
}
if (totalRows != 0)
{
rList = new List<int[]>();
for (int i = 0; i < totalRows; i++)
{
rList.Add(new int[iList.Count]);
}
int repeatNum = totalRows;//该值表示批量内应该重复的次数
int repeatPa;//表示批量执行次数,每个重复应该出现多少次
int intervalNum;//表示每批重复应该有的间隔
for (int i = 0; i < iList.Count; i++)
{
repeatNum /= iList[i];
repeatPa = totalRows / repeatNum / iList[i];
intervalNum = repeatNum * iList[i];
for (int m = 0; m < repeatNum; m++)
{
for (int n = 0; n < repeatPa; n++)
{
for (int l = 0; l < iList[i]; l++)
{
rList[intervalNum * n + m + l * repeatNum][i] = l;
}
}
}
}
}