C#中多集合组合使用方法,主要用到 Enumerable.Join方法
var skuInfoList = new Dictionary<int, List<long>>(); var ctParamList = new List<long>(); foreach (var sku in skuList) { var singleSku = sku.Split(‘|‘); ctParamList = new List<long>(); foreach (var skuParam in skuParamList) { var singleSkuParam = skuParam.Split(‘:‘); if (singleSku[0] == singleSkuParam[0]) { var singleParam = singleSkuParam[1].Split(‘|‘); ctParamList.Add(Convert.ToInt64(singleParam[0])); } } skuInfoList.Add(Convert.ToInt32(singleSku[0]), ctParamList); } var res = new List<List<long>>() { new List<long>() }; Func<List<long>, List<List<long>>> func = lst => { return res.Join(lst, x => 1, x => 1, (x, y) => { var tem = x.ToList(); tem.Add(y); return tem; }).ToList(); }; foreach (var skuInfo in skuInfoList) res.AddRange(func(skuInfo.Value));
关键代码:
var res = new List<List<long>>() { new List<long>() }; Func<List<long>, List<List<long>>> func = lst => { return res.Join(lst, x => 1, x => 1, (x, y) => { var tem = x.ToList(); tem.Add(y); return tem; }).ToList(); };
原文地址:https://www.cnblogs.com/yangyuping/p/9365242.html
时间: 2024-11-13 09:47:19