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. window.close(); 关闭浏览器窗口js代码

    序号 关闭代码 需要确认 无任何作用 无需确认 测试 1 window.close() IE7 firefox,chrome,safari Opera Close 2 window.opener=nu ...

  2. c++函数常用

    isalnum 判断一个字符是否是字符类的数字或字母isalpha 判断一个字符是否是字母isblank 判断一个字符是否是空白字符(空格,水平制表符,TAB)iscntrl 判断一个控制符(ASCI ...

  3. python 全栈开发,Day2(正式)

    一.in的使用 in 操作符用于判断关键字是否存在于变量中 a = '男孩wusir' print('男孩' in a) 执行输出: True in是整体匹配,不会拆分匹配. a = '男孩wusir ...

  4. 问题排查:The requested URL /test/index.jsp was not found on this server

    问题描述 添加一个新模块,部署在服务器上.服务器上还部署有其他模块且访问正常,新模块和其他模块共用同一个域名.服务部署之后,请求如下: http://my.domain.com/test/index. ...

  5. kubernete的证书总结

    服务端保留公钥和私钥,客户端使用root CA认证服务端的公钥. kubernetes的证书类型主要分为3类: serving CA: 用于签署serving证书,该证书用于加密https通信.用于签 ...

  6. WinSock 异步I/O模型-1

    异步选择(WSAAsyncSelect):异步选择基本定义 异步选择(WSAAsyncSelect)模型是一个有用的异步 I/O 模型.利用这个模型,应用程序可在一个套接字上,接收以 Windows ...

  7. Redis主从集群的Sentinel配置

    http://www.cnblogs.com/LiZhiW/p/4851631.html

  8. Vue项目环境搭建(node+webpack)

    安装node.js 下载地址:https://nodejs.org/en/download/ node -v //查看node.js版本 项目环境配置: 安装vue-cli:npm install - ...

  9. [css 实践篇] 解决悬浮的<header> <footer>遮挡内容的处理技巧

    我写的实践篇 都是自己在实践项目所遇到的 "拦路虎" 还是很有借鉴的意义的.(实践才是检验真理的唯一标准呀),废话不多说,进去正题 position: fixed 绝对固定底部后会 ...

  10. Linux下的指令:tail

    tail指令常用来查看服务器中的日志信息. 有的时候,需要实时获取日志信息. 比如,我们向服务器发送了一个请求,此时日志有更新,而我们又想实时看到尾部更新的内容. 这时候可以使用指令: tail -f ...