你的位置:首页 > ASP.net教程

[ASP.net教程]Linq之Lambda表达式


一 什么是LINQ?

LINQ即Language Integrated Query(语言集成查询),LINQ是集成到C#和Visual Basic.NET这些语言中用于提供查询数据能力的一个新特性。

二 简单的Linq例子。(简单形式我就不介绍了,主要以Lambda形式介绍)。

 1  首先创建一个实体对象类并赋值。

 public class Person {     public int PId { get; set; } // 自增Id     public string Name { get; set; }     public int Age { get; set; }     public int JobId { get; set; } //职业Id } List<Person> pA = new List<Person>();      pA.Add(new Person() { Pid = 1, Name = "张三", Age = 16, JobId = 1 });      pA.Add(new Person() { Pid = 2, Name = "小红", Age = 18, JobId = 2 });      PA.Add(new Person() { Pid = 3, Name = "王武", Age = 20, JobId = 3 });      pA.Add(new Person() { Pid = 4, Name = "小梅", Age = 17, JobId= 4 });        pA.Add(new Person() { Pid = 5, Name = "小李", Age = 24, JobId= 3 }); public class Job {    public int JobId { get; set; } //自增ID    public string JobName { get; set; }    public int WorkAge { get; set; }}List<Job> jB = new List<Job>();      jB.Add(new Job() { JobId = 1, JobName = "制造业", WorkAge = 3 });      jB.Add(new Job() { JobId = 2, JobName = "IT行业", WorkAge = 5 });      jB.Add(new Job() { JobId = 3, JobName = "建筑业", WorkAge = 2 });      jB.Add(new Job() { JobId = 4, JobName = "金融业", WorkAge = 1 });    

View Code