当前位置:网站首页>[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();
边栏推荐
- Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
- LeetCode122. 买卖股票的最佳时机II
- [book club issue 13] packaging format of video files
- Lumiprobe non fluorescent alkyne research - dbco NHS ester
- Leetcode56. consolidation interval
- 什么是接口?什么是接口测试?
- Leetcode: expand a binary tree into a linked list_ one hundred and fourteen
- Ehcache configuration data, convenient for self checking
- 【读书会第13期】视频文件的封装格式
- LeetCode226. 翻转二叉树
猜你喜欢

QJsonObject的使用示例

The further application of Li Kou tree

Security dilemma of NFT liquidity agreement - Analysis of the hacked event of NFT loan agreement xcarnival

Progress in visual weakly supervised learning

Lumiprobe non fluorescent alkyne research - dbco NHS ester

华为云的AI深潜之旅

接口测试流程

How to analyze the relationship between enterprise digital transformation and data asset management?
![[software test] 2022 national unified college enrollment examination](/img/9a/d76d7eb30a097d364fef28c2230e1a.png)
[software test] 2022 national unified college enrollment examination

Ehcache configuration data, convenient for self checking
随机推荐
Leetcode daily question - 324 Swing sort II
LeetCode560. 和为K的子数组
Web 自动化环境搭建
17 `bs object Node name h3 Parent ` parents get parent node ancestor node
Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
Leetcode daily question - 710 Random numbers in the blacklist
PHP login problem
Pyechart drawing multiple Y-axis line graphs
Leetcode: merge K ascending linked lists_ twenty-three
How to make up the PMP Exam? How much is the make-up exam?
Lua源码剖析:一. lua变量类型可变特性在C代码中实现。
【笔记:模拟MOS集成电路】带隙基准(基本原理+电流模+电压模电路详解)
认识Web自动化测试
接口用例设计
Alist+raidrive gives the computer a complete 8billion GB hard disk drive
LeetCode877. 石子游戏
在哪个软件上开户比较安全,开户流程是什么?
Microsoft's exclusive payment function has also been perfectly unlocked
Leetcode: expand a binary tree into a linked list_ one hundred and fourteen
LeetCode117. Populate the next right node pointer for each node_ II