文章目录
- C#之linq和lamda表达式GroupBy分组拼接字符串
- 业务需求
- 核心代码
- 调试
C#之linq和lamda表达式GroupBy分组拼接字符串
业务需求
点击提示信息,如:“售后单【SH001】序列号【001,002,006】;售后单【SH002】序列号【003,007,009】。已经过了质保期,确认要继续关闭吗”
核心代码
//lamda表达式var errorMsgObj = getNoPay.GroupBy(s => s["FBILLNO"] + "").Select(d=>new { BillNo=d.Key,NumberList=string.Join(",",d.Select(f=>f["FNUMBER"]+""))}).ToList();//Linq
var resultMsg = (from item in getNoPaygroup item by item["FBILLNO"] into glet numbers = g.Select(b => b["FNUMBER"]).ToArray()select new{BillNo = g.Key,NumberList = string.Join(",", numbers)}).ToList();
调试
集合数据:
展示数据: