我有一个属性类:Row, Seat.例如,我们有以下数据:
Row Seat
1 1
1 2
1 3
2 4
2 5
Run Code Online (Sandbox Code Playgroud)
我想要Dictionary<int,int>包含Row作为键的返回,以及行中的座位数作为值.对于上面的例子,字典将包含两个记录:
Key Value
1 3
2 2
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢.
list.GroupBy(x => x.Row)
.ToDictionary(x => x.Key, x => x.Count());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
140 次 |
| 最近记录: |