C#Linq语句与List结合使用
2015-08-20 11:49
567 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication6 { public class Student { private int ID; private string name; private int age; public Student(int id, string _name,int _age) { ID = id; name = _name; age = _age; } public int _ID { get { return ID; } set { ID = value; } } public string Name { get { return name; } set { name = value; } } public int Age { get { return age; } set { age = value; } } } public class StudenManager { public List<Student> sm = new List<Student>(); public void Attach(Student s) { sm.Add(s); } public void IDOutPut() { Console.WriteLine(sm.OrderByDescending(item => item.Age).Last()._ID); } public void AgeOutPut(int age) { Console.WriteLine(sm.Find(item => item.Age == age).Age); } } class Program { static void Main(string[] args) { Student s1 = new Student(1,"xiaoming",18); Student s2 = new Student(2, "xiaowang", 15); Student s3 = new Student(3, "xiaoli", 16); StudenManager sma = new StudenManager(); sma.Attach(s1); sma.Attach(s2); sma.Attach(s3); sma.IDOutPut(); sma.AgeOutPut(s1.Age); } } }
http://stackoverflow.com/questions/18372910/find-max-min-list-item-using-linq
相关文章推荐
- C# DataGridView设置某一格为组合框
- C# Settings使用小结
- C# Serializable
- C# TextBox 只能输入数字
- C#操作Active Directory(AD)详解
- C#的抽象类
- C#调用SSIS包及读取DataReader目标
- winform 窗体特效
- C#模拟PrtScn实现截屏预备知识--剪贴板操作
- C#模拟PrtScn实现截屏预备知识--剪贴板操作
- C# ContentType类型汇总
- c#反射
- C# 关闭浏览器
- C#中override和overload的区别
- C#中Abstract和Virtual的区别
- C#模拟PrtScn实现截屏预备知识--keybd_event使用方法
- C#模拟PrtScn实现截屏预备知识--keybd_event使用方法
- C#中ArrayList 与 string、string[]数组 的转换
- 模板约束
- Csharp: read excel file using Open XML SDK 2.5