list group by 问题咨询

hiksoho 2018-04-24 02:57:33
var ls2 = new List<Dictionary<string, int>>();
ls2.Add(new Dictionary<string, int>
{
{"a",1},
{"b",2}
});
ls2.Add(new Dictionary<string, int>
{
{"a",3},
{"c",4}
});
ls2.Add(new Dictionary<string, int>
{
{"a",1},
{"c",5}
});

请问,有什么linq或者快方法可以得出 ls2 下group by key=a 时 value 得到 1,3 ?
...全文
217 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sprints_昊天 2018-04-24
  • 打赏
  • 举报
回复
6666还有这种东西啊
  • 打赏
  • 举报
回复
ls2.SelectMany(d=>d.Select(kv=>kv)).GroupBy(p=>p.Key)
sprints_昊天 2018-04-24
  • 打赏
  • 举报
回复
...这是在搞什么飞机 把字典放在list里 还要根据字典的键分组???

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧