我定義一個物件,裡面有以下資訊...
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最大的嗎??