实体集合去重合并,并且指定属性相加

//chgDtl获取实体ChgDtlJbVo集合
                //去重合并数量
                List<ChgDtlJbVo> chgDtlsResult = new List<ChgDtlJbVo>();
                foreach(var  s in chgDtls)
                {
                    //根据指定属性找到相同的实体
                    var item = chgDtlsResult.Find(a => a.ChgDtlId == s.ChgDtlId);
                    if (item != null)
                    {
                        //相同的实体进行数量合并
                        item.ChgAmount += s.ChgAmount;
                    }
                    else
                    {
                        chgDtlsResult.Add(s);
                    }
                }
原文地址:https://www.cnblogs.com/yuanshuo/p/13619069.html