Lambda表达式
- 本质是个方法
- 在使用lambda表达式时,编译器会在在使用lambda表达式中的类会产生一个类中类
- 每一个lambda表达式对应类中类中静态委托
- 实际上是类中类里面的一个internal方法,会被绑定在类中类的静态委托

陈述式语法查询
class Student{ string name {get; set;} int id {get; set;} int age {get; set;}}public static class ExtendMethod{ //基于委托封装解耦 //泛型 public List<T> IWhere<T>(this List<T> source, Func<List<T>, bool> func) { var list = new List<T>(); foreach(var item in source) { if (func.Invoke()) { list.Add(item); } } return list; } //迭代器,按需获取 public IEnumerable<T> MyWhere<T>(this IEnumerable<T> source, Func<List<T>, bool> func) { if (source == null) { throw new Exception("source is null") } if (func == null) { throw new Exception("func is null") } foreach(var item in source) { if (func.Invoke()) { yield item; } } }}var result = list.MyWhere<Student>(s => s.Age < 30)
Linq to object(Enumerable)
<a name="8M6lV"></a>## Where- 完成对数据集合的过滤,通过委托封装完成通用代码,泛型和迭代器去提供特性```csharpvar linqWhere = list.Where<Student>(s => s.Age < 30);
Select
- 完成对数据集合的转换,通过委托封装完成通用代码,泛型和迭代器去提供特性

var linqWhere = list.Where<Student>(s => s.Age < 30) .Select<Student, int>(s => s.Name.Length); var linqWhere = list.Where<Student>(s => s.Age < 30) .Select(s => new { Id = s.Id, Name = s.Name; Length = s.Name.Length });
Linq to sql(Queryable)
- 封装了通用代码(ADO.NET)
- 表达式目录树解析SQL