Contains

    public class StudentEquality : IEqualityComparer<Student>
{ public static StudentEquality Instance { get; set; } private StudentEquality()
{ } static StudentEquality()
{
Instance = new StudentEquality();
} public bool Equals(Student x, Student y)
{
if (x == null || y == null)
{
return false;
} if (x.StudentID == y.StudentID)
{
return true;
} return false;
} public int GetHashCode(Student obj)
{
return obj.GetHashCode();
}
}
            List<Student> studentList = new List<Student>() {
new Student() { StudentID = , StudentName = "Zohn", StandardID = },
new Student() { StudentID = , StudentName = "Moin", StandardID = },
new Student() { StudentID = , StudentName = "Bill", StandardID = },
new Student() { StudentID = , StudentName = "Ram1" , StandardID = },
new Student() { StudentID = , StudentName = "Ron1123", StandardID = }
}; Student s = new Student() { StudentID = , StudentName = "Ron1123", StandardID = };
bool res = studentList.Contains(s, StudentEquality.Instance);
Console.WriteLine("Contains = " + res);// True

Max

    public class StudentComparable : IComparable<StudentComparable>
{
public Student Student { get; set; } public int CompareTo(StudentComparable other)
{
if (Student.StudentName.Length > other.Student.StudentName.Length)
{
return ;
} if (Student.StudentName.Length == other.Student.StudentName.Length)
{
return ;
}
return -;
}
}
            IList<Student> studentList = new List<Student>() {
new Student() { StudentID = , StudentName = "Zohn", StandardID = },
new Student() { StudentID = , StudentName = "Moin", StandardID = },
new Student() { StudentID = , StudentName = "Bill", StandardID = },
new Student() { StudentID = , StudentName = "Ram1" , StandardID = },
new Student() { StudentID = , StudentName = "Ron1123", StandardID = }
};
//选出最长的名字的 Student
StudentComparable max = studentList.Max(m => new StudentComparable { Student = m });
Console.WriteLine(JsonConvert.SerializeObject(max.Student));
Console.Read();

Linq 对象的比较 Contains,Max的更多相关文章

  1. Newtonsoft.Json.Linq对象读取DataSet数据

    Newtonsoft.Json.Linq对象读取DataSet数据: private void button4_Click(object sender, EventArgs e)        {   ...

  2. Linq中max min sum avarage count的使用

    一.Max最大值 static void Main(string[] args) { //Max求最大值 ,,,,,,,,,}; //方法1 Linq语句+Linq方法 var result = (f ...

  3. 【转】Linq Group by

    http://www.cnblogs.com/death029/archive/2011/07/23/2114877.html 1.简单形式: var q = from p in db.Product ...

  4. Linq使用Group By 1

    Linq使用Group By 1 1.简单形式: var q = from p in db.Products group p by p.CategoryID into g select g; 语句描述 ...

  5. Linq操作

    Linq使用Group By 1 1.简单形式: var q = from p in db.Products group p by p.CategoryID into g select g; 语句描述 ...

  6. linq 常用语句

    自己练习的 switch (productDataAnalysisQuery.DataType) { : var data = (from hp in GPEcontext.hbl_product j ...

  7. LINQ(隐式表达式、lambda 表达式)

    .NET 中一项突破性的创新是 LINQ(Language Integrated Query,语言集成查询),这组语言扩展让你能够不必离开舒适的 C# 语言执行查询. LINQ 定义了用于构建查询表达 ...

  8. LINQ to XML学习笔记

    一.XML基础知识 1.XML:可扩展标记语言 Extensible Markup Language ,提供了一种保存数据的格式,数据可以通过这种格式很容易地在不同的应用程序之间实现共享. 2.使用X ...

  9. linq中的GroupBy总结

    1.简单形式: var q = from p in db.Products group p by p.CategoryID into g select g; 语句描述:Linq使用Group By按C ...

随机推荐

  1. 深度剖析HashMap的数据存储实现原理(看完必懂篇)

    深度剖析HashMap的数据存储实现原理(看完必懂篇) 具体的原理分析可以参考一下两篇文章,有透彻的分析! 参考资料: 1. https://www.jianshu.com/p/17177c12f84 ...

  2. [设计]GUI设计规范的规范

    1. 前言 很多著名的软件企业都有GUI设计规范,如 Apple 和 Google,得益于这些设计规范(或者叫指南),设计者才可以开发出符合平台视觉及交互要求的UI.其实除了这些大公司,软件公司都最好 ...

  3. 特定场景下Ajax技术的使用

    ajax介绍 jax技术包含了几种技术:javascript.xml.css.xstl.dom.xhtml和XMLHttpRequest七种技术,所以ajax就像是粘合剂把七种技术整合到一起,从而发挥 ...

  4. 十大经典排序算法最强总结(含JAVA代码实现)

    最近几天在研究排序算法,看了很多博客,发现网上有的文章中对排序算法解释的并不是很透彻,而且有很多代码都是错误的,例如有的文章中在“桶排序”算法中对每个桶进行排序直接使用了Collection.sort ...

  5. 性能优化之reflow和repaint

    本文主要介绍一下什么是reflow,repaint, 怎样避免它们造成的不良影响, 怎么通过工具查看分析它们. 一.首先对浏览器渲染引擎下网页呈现过程简要说一下: 浏览器的渲染引擎开始解析html构建 ...

  6. spring+springMVC 整合 MongoDB 实现注册登录

    发现一入手 MongoDB,便无法脱离,简要说一下,MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的. 也是在 Nosql 中我最喜欢的一种 ...

  7. centos7上关闭防火墙

    centos7上默认开启的是+firewalld,关闭了iptables 停止防护墙: systemctl stop firewalld.service 开机不启动: systemctl disabl ...

  8. u-boot的SPL源码流程分析

    上次梳理了一下SPL的基本概念和代码总体思路,这次就针对代码跑的流程做个梳理.SPL中,入口在u-boot-spl.lds中 ENTRY(_start) SECTIONS { .text : { __ ...

  9. Idea中开启assert断言

    先打开相应的配置面板,有以下两种方式.   然后在VM栏里输入 -enableassertions 或者 -ea 就好了 然后编写程序试试 我的目录结构如下:(因为Main class那里要写类的全限 ...

  10. 选择排序—堆排序(Heap Sort) 没看明白,不解释

    堆排序是一种树形选择排序,是对直接选择排序的有效改进. 基本思想: 堆的定义如下:具有n个元素的序列(k1,k2,...,kn),当且仅当满足 时称之为堆.由堆的定义可以看出,堆顶元素(即第一个元素) ...