当前位置:网站首页>C LINQ de Duplication & de duplication sum
C LINQ de Duplication & de duplication sum
2022-07-25 17:51:00 【Time has lived up to expectations】
Linq Three ways of weight removal
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
List<_model> _list = new List<_model>();
_list.Add(new _model() {
_sum = 1, _id = 1, _int = 1 });
_list.Add(new _model() {
_sum = 3, _id = 1, _int = 2 });
_list.Add(new _model() {
_sum = 7, _id = 2, _int = 1 });
_list.Add(new _model() {
_sum = 2, _id = 3, _int = 1 });
_list.Add(new _model() {
_sum = 4, _id = 3, _int = 2 });
_list.Add(new _model() {
_sum = 9, _id = 3, _int = 3 });
// Returns a list of
var _list1 = _list.GroupBy(i => i._id).Select(i => i.OrderByDescending(i => i._int).First()).ToList();
foreach (var item in _list1)
{
Console.WriteLine(item._sum);
Console.WriteLine(item._id);
Console.WriteLine(item._int);
}
// Return summation ( Single condition sort )
var _list2 = _list.GroupBy(i => i._id).Select(i => new {
i.Key, _sum = i.Sum(o=>o._sum) }).ToList();
foreach (var item in _list2)
{
Console.WriteLine(item.Key);
Console.WriteLine(item._sum);
}
// Return summation ( Multiple conditional sorting )
var _list3 = _list.GroupBy(i => new {
i._id,i._int}).Select(i => new {
i.Key, _sum = i.Sum(o => o._sum) }).ToList();
foreach (var item in _list3)
{
Console.WriteLine(item.Key._id);
Console.WriteLine(item.Key._int);
Console.WriteLine(item._sum);
}
//===========================================================================
Console.ReadKey();
}
public class _model
{
public int _sum {
get; set; }
public int _id {
get; set; }
public int _int {
get; set; }
}
}
边栏推荐
- After consulting about how to deal with DDL in Flink SQL client, how to add fields and jobs to the mapping table in Fink SQL?
- Redis源码与设计剖析 -- 16.AOF持久化机制
- [cadence Allegro PCB design] error: possible pin type conflict gnd/vcc power connected to output
- OSPF --- open shortest priority path protocol
- 食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!
- 栈的顺序存储结构,链式存储结构及实现
- Tkinter module advanced operations (I) -- transparent buttons, transparent text boxes, custom buttons and custom text boxes
- Redistemplate solves the problem of oversold inventory in the seckill system with high speed - redis transaction + optimistic lock mechanism
- PageHelper还能结合Lambda表达式实现简洁的分页封装
- Principle and implementation of UDP penetration NAT in P2P
猜你喜欢

"Digital security" alert NFT's seven Scams

Cet
![[solution] the Microsoft edge browser has the problem of](/img/47/7e20a4f1e04577153e7cf0a6c61f26.png)
[solution] the Microsoft edge browser has the problem of "unable to access this page"

世界各地的标志性建筑物

绘制pdf表格 (二) 通过itext实现在pdf中绘制excel表格样式设置中文字体、水印、logo、页眉、页码

Hcip first day experiment

Unity 贝塞尔曲线的创建

How to fix the first row title when scrolling down in Excel table / WPS table?

Three dimensional function display of gray image

绘制pdf表格 (一) 通过itext实现在pdf中绘制excel表格样式并且实现下载(支持中文字体)
随机推荐
mysql case when
What is an IP SSL certificate and how to apply for it?
PHP解决并发问题的几种实现
四六级
Take you to a preliminary understanding of multiparty secure computing (MPC)
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
IDEA集成SVN代码管理常用功能
食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!
Which futures account is the best and safest
Brief introduction to clustered index, secondary index, index push down
SVN客户端(TortoiseSVN)安装及使用说明
Redis source code and design analysis -- 17. Redis event processing
How to fix the first row title when scrolling down in Excel table / WPS table?
自动化测试 PO设计模型
WPF 实现用户头像选择器
I2C communication - sequence diagram
面试官:说说 log.Fatal 和 panic 的区别
Is it safe to open a futures account online? How to apply for a low handling fee?
【Cadence Allegro PCB设计】error: Possible pin type conflict GND/VCC Power Connected to Output
Mock服务moco系列(二)- Json格式、File文件、Header、Cookie、解决中文乱码