1. 程式人生 > >C#中多集合組合實現

C#中多集合組合實現

實現 ram for var fun list() int32 class sin

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();
                };

C#中多集合組合實現