当前位置:网站首页>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; }
}
}
边栏推荐
猜你喜欢

面试官:说说 log.Fatal 和 panic 的区别

TME2022校园招聘后台开发/运营开发/业务运维/应用开发笔试(I)编程题的一点自我分析

Hcip first day experiment

Interviewer: talk about log The difference between fatal and panic

Excel表格 / WPS表格中怎么在下拉滚动时让第一行标题固定住?

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

I2C communication - sequence diagram

一篇文章了解超声波加湿器

Installation and operation instructions of SVN client (TortoiseSVN)

I'm also drunk. Eureka delayed registration and this pit!
随机推荐
Mongodb cluster and sharding
I2C communication - sequence diagram
RestTemplate通过泛型实现POST、PUT、DELETE、GET、集合请求以及文件上传(可批量文件、可带参数)的统一封装(可打印日志)
PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation
带你初步了解多方安全计算(MPC)
What is an IP SSL certificate and how to apply for it?
Step by step introduction of sqlsugar based development framework (13) -- package the upload component based on elementplus, which is convenient for the project
SVN客户端(TortoiseSVN)安装及使用说明
软件测试基础知识(思维导图)
Dating activity records
多项式相加
我也是醉了,Eureka 延迟注册还有这个坑!
Principle and implementation of UDP penetration NAT in P2P
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
什么是 IP SSL 证书,如何申请?
实时黄金交易平台哪个可靠安全?
【无标题】
Postman get started quickly
栈的顺序存储结构,链式存储结构及实现
Tkinter module advanced operations (I) -- transparent buttons, transparent text boxes, custom buttons and custom text boxes