简体   繁体   English

如何使用LINQ从DISTINCT行聚合值

[英]How to aggregate the value from DISTINCT row using LINQ

I have following data: 我有以下数据:

Name    Priority
A       3
A       5
B       1
C       1
C       3
C       2

I want to get list of distinct names with All priority, so the result 我想获得具有所有优先级的不同名称的列表,因此结果

would look like: 看起来像:

Name    priorities
A       3,5
B       1
C       1,3,2

How can I use Linq to do that? 我如何使用Linq来做到这一点?

Use this overload of GroupBy 使用GroupBy的这个重载

var grouped = myList.GroupBy(i => i.Name, i => i.Priority, 
    (Name, Priorities) => new {Name, Priorities});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM