static void Main(string[] args)
{
List<Person> persons = new List<Person>();
persons.Add(, ClassId = ", Name = "小明" });
persons.Add(, ClassId = ", Name = "小明2" });
persons.Add(, ClassId = ", Name = "小明3" });
persons.Add(, ClassId = ", Name = "小明4" });
persons.Add(, ClassId = ", Name = "小明5" });
persons.Add(, ClassId = ", Name = "小明6" });
List<Classes> classes = new List<Classes>();
classes.Add(", ClassName = "1年级" });
classes.Add(", ClassName = "2年级" });
classes.Add(", ClassName = "3年级" });
classes.Add(", ClassName = "4年级" });
classes.Add(", ClassName = "5年级" });
//查询年纪大于12 小于17的学生
List<Person> person = ( && p.Age < select p).ToList<Person>();
//表连接
var datas = from p in persons
join c in classes on p.ClassId equals c.ClassId
select new { p.Name, p.Age, c.ClassName };
//查询每个班级每个年龄段的人数 并排序
var data = from c in classes
join p in persons on c.ClassId equals p.ClassId
group c by new {c.ClassName,p.Age} into g
orderby g.Count() descending
select new { g.Key,Count = g.Count() }
;
Console.ReadKey();
}
}