.NET 3.x新特性之Lambda表达式(3) 5 };6 //取得people中Age为23的Person实例。7 IEnumerable<Person> results = people.Where(p => p.Age == 23);8 //计算people中的平均岁数。9 int perAge = people.Average(p => p.Age);
看到Lambda表达式了吗?p=>p这个就是Lambda表达式,当然Where和Average就是扩展方法,是LinQ的一个扩展方法。当然我们在C#或者说在.NET 2.0中也能够做到,但是可没有那么简单(其实也不难),下面我们看一下在.NET 2.0中的实现方法:
1 List<Person> people = new List<Person>