/* Linq: Language INtegrated Query语言级集成查询 LinQ通常在数组,泛型集合,IEnumerable等 关键字:from ,in , where , orderby, select new {v1=stra,v1=strb} from: 变量或对象 多个数据源 嵌套语句 in:查询的数据源 where: 条件 可允许多个where字句,但表示的是并列关系,表达式最好用()括起来 orderby: 指定排序字段,可以是升序或降序,多个间逗号分隔 select:指定返回目标内容 group:对象 by 对象的属性或字段,分组 join:连接多个数据源,后面必须跟 on 关键字 LInq查询必须是以select子句或者group by子句结尾 lanmda 表达式 "=>" */ #endregion #region 查询数组 Console.WriteLine("查询数组\r\n"); int[] arr = new int[] { 12, 34, 45, 3, 11, 18 }; int[] arr2 = new int[] { 25, 58, 34, 94, 43, 38, 48, 9 }; //匿名对象, 查询变量 var m_1 = from m in arr select m; //where子句 var m0 = from m in arr where m % 2 == 0 select m; //多个where子句是并列关系 var m2 = from m in arr where m >= 10 where m <= 20 where m % 2 == 0 select m; //也可以这样写 var m3 = from m in arr where (m >= 10) && (m <= 20) && (m % 2 == 0) select m; //orderby排序,ascending-升序;descending-降序 多个排序条件使用逗号分隔 var m1 = from n in arr where n % 2 == 1 orderby n ascending select n; //多数据源 var m4 = from m in arr from n in arr2 where m == n select new { var1 = m, var2 = n }; //select子句后面可以跟 匿名对象 //可以给匿名对象的成员取别名 foreach (var item in m4) { Console.WriteLine(item); }