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. centos7.2 配置内网ntp服务器进行时间同步

    (一)修改/etc/ntp.conf 配置文件,注意红色部分,其他部分不需要改  ########################################################### ...

  2. python-kafka实现produce与consumer

    1.python-kafka: api送上:https://kafka-python.readthedocs.io/en/latest/apidoc/KafkaConsumer.html 2.实现一个 ...

  3. Spring Boot 2.0(四):使用 Docker 部署 Spring Boot

    Docker 技术发展为微服务落地提供了更加便利的环境,使用 Docker 部署 Spring Boot 其实非常简单,这篇文章我们就来简单学习下. 首先构建一个简单的 Spring Boot 项目, ...

  4. 一年java工作经验的面试题总结(持续更新中)

    本人是17年6月份毕业的,3月份出来实习,算起来也是工作一年了吧,金三银四,博主也考虑换一份工作,于是最近面试了几家,总结一下面试中的问题,大家一起交流学习. 第一次面试  ①说下java类的加载 ② ...

  5. netcore 使用surging框架发布到docker

    demo运行在windows的docker中,系统是win10,所以需要先下载Docker for Windows,安装完毕后系统会重启,然后桌面上可以找到Docker for Windows的快捷图 ...

  6. [UWP]理解ControlTemplate中的VisualTransition

    1. 前言 VisualTransition是控件模板中的重要组成部分,无论是自定义控件或者修改控件样式都会接触到VisualTransition.明明这么重要,博客园上好像都没多少关于VisualT ...

  7. centos上的grub文件修改

    centos上的grub文件修改 author:headsen chen 2017-10-10  17:36:42 个人原创,转载请注明作者和出处,否则追究法律责任 1,centos6上的修改:vim ...

  8. 在java或 js中的日期时间转换问题

    1.在js中需要求的当前日期的周一和周日 var now = new Date(); // 当前日期时间对象 var date = now.getDate(); // 当前是几号:当前日期在一个月中的 ...

  9. python装饰器使用

    看了不少python关于装饰器文章,觉得还挺实用,发贴来mark一下(以前做笔记总会长时间不看就忘记,放这里应该不会忘了吧 - -) 先来看一个简单的知识点: def a(): print(" ...

  10. 【Flask】 项目结构说明

    项目结构 Flask的一大优势就是其极其轻量化.但是也需要注意到,如果我们要用Flask做一个大项目的话,把所有代码写在一个文件里肯定是不合适的.非常难以维护.但是和Django这种框架又不一样,Fl ...