Lambda与LINQ
Lambda与LINQ写法对比:
上为Lambda
下为LINQ
- 显示指定列
- Students.select(u=>(new {Name=u.Sname,Address=u.Saddress}))
- from s in Students Select new {s.Sname,s.Saddress}
- 有条件显示指定列
- Students.Where(s=>((s.SID<10)&&(s.Sname.Length<10)))
.Select(s=> new{Name = s.Sname,Sdd = s.Saddress})
- From s in Students
Where s.SID<10&& s.Sname.Length<10
Select new{Name = s.Sname,Sdd = s.Saddress}
- 排序为升序
- Students.OrderBy(s=>s.SID)
- From s in Students
Orderby s.SID
Select s
- 排序为降序
- Students.OrderByDescending(s=>SID).Select(s=>s)