当前位置:网站首页>[linq]c list type grouping sum
[linq]c list type grouping sum
2022-06-28 21:49:00 【Xiamen dezai】
C# List Type group summation
List<Person> personList = new List<Person>();
Person p1 = new Person();
p1.Name = "Bob";
p1.Age = "14";
p1.Salary = 1200;
personList.Add(p1);
Person p2 = new Person();
p2.Name = "Bob";
p2.Age = "14";
p2.Salary = 1500;
personList.Add(p2);
Person p3 = new Person();
p3.Name = "Ken";
p3.Age = "56";
p3.Salary = 1000;
personList.Add(p3);
var groupList = personList.GroupBy(m => new {
m.Name, m.Age }).
Select(a => new
{
Name = a.Key.Name,
Salary = a.Sum(c=>c.Salary)
}).ToList();
foreach (var item in groupList)
{
Console.WriteLine("Name:{0}--Salary:{1}", item.Name,item.Salary);
}
Console.ReadKey();
边栏推荐
- Leetcode: merge K ascending linked lists_ twenty-three
- How do I download videos? Look at the super simple method!
- Flask - Summary
- Workplace tips | understanding the advantages of the position "knowing people"
- The blocks problem (uva101) Purple Book p110vector application
- Construction and application of urban brain knowledge map
- 2022年股票在手机上开户安全吗?找谁可以办理?
- Native implementation Net 5.0+ custom log
- Leetcode daily question - 710 Random numbers in the blacklist
- Postman introduction and installation steps
猜你喜欢

Pyechart drawing multiple Y-axis line graphs

An artifact extracted from a well-known software and paid by a group of people

Zero foundation self-study SQL course | complete collection of date functions in SQL

How do I download videos? Look at the super simple method!

Construction and application of urban brain knowledge map

PHP login problem

Study on luminiprobe non fluorescent azide -- 3-azido propanol

Bitbucket failed to pull the warehouse Using SSH

华为云的AI深潜之旅

Lumiprobe proteorange protein gel dye instructions
随机推荐
Anr no response introduction
LeetCode56. 合并区间
LeetCode560. 和为K的子数组
为什么要使用 Rust 语言?
LeetCode213. 打家劫舍II
Golang JSON serializing and deserializing strings deserializing to map[string]interface{}
Anti rabbit dylight 488 abbkine universal immunofluorescence (if) toolbox
CVPR 2022 𞓜 a creative and aesthetic text generation method! Support any input
【激活函数】
Web 自动化环境搭建
LeetCode122. The best time to buy and sell stocks II
be careful! The PMP emergency postponement exam is due today!
开通股票炒股账号安全吗?是靠谱的吗?
Security dilemma of NFT liquidity agreement - Analysis of the hacked event of NFT loan agreement xcarnival
LeetCode116. 填充每个节点的下一个右侧节点指针
QJsonObject的使用示例
LeetCode:二叉树展开为链表_114
Bitbucket 使用 SSH 拉取仓库失败的问题
Web automation tool selection
Leetcode56. consolidation interval