我定义一个物件,里面有以下资讯...
public class Person {
public string Name;
public int Age;
public string Sex;
};
我使用一个List容器来装此物件...
List<Person> PerList = new List<Person>(){
new Person(){ Name = "Sam", Age = 50, Sex = "Man" },
new Person(){ Name = "Amy", Age = 30, Sex = "Woman"},
new Person(){ Name = "Andy", Age = 30, Sex = "Man"},
new Person(){ Name = "Jacky", Age = 60, Sex = "Man"},
new Person(){ Name = "Peter", Age = 65, Sex = "Man"},
new Person(){ Name = "Susan", Age = 45, Sex = "Woman"},
new Person(){ Name = "Jeff", Age = 65, Sex = "Man"},
new Person(){ Name = "Mary", Age = 63, Sex = "Woman" };
假设,我有一组资料如上,而我希望可以直接过滤掉其他不需要的资料。
我希望可以"保留" Age 前三名最大的...
也就是说,剩下Mary,Jacky,Peter,Jeff...
想请问一下,如果透过Lambda或是LINQ有办法过滤出前三名Age最大的吗??