C#中多集合组合实现

2021-03-27 02:24

阅读:865

标签:ret   ctp   list   func   inf   each   long   class   ble   

C#中多集合组合使用方法,主要用到 Enumerable.Join方法

var skuInfoList = new Dictionaryint, Listlong>>();
                var ctParamList = new Listlong>();
                foreach (var sku in skuList)
                {
                    var singleSku = sku.Split(|);
                    ctParamList = new Listlong>();
                    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 Listlong>>() { new Listlong>() };
                Funclong>, Listlong>>> 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 Listlong>>() { new Listlong>() };
                Funclong>, Listlong>>> func = lst =>
                {
                    return res.Join(lst, x => 1, x => 1, (x, y) =>
                    {
                        var tem = x.ToList();
                        tem.Add(y);
                        return tem;
                    }).ToList();
                };

 

C#中多集合组合实现

标签:ret   ctp   list   func   inf   each   long   class   ble   

原文地址:https://www.cnblogs.com/yangyuping/p/9365242.html


评论


亲,登录后才可以留言!