标签:
//Linq:language Intergarted Query 语言整合查询 //select * from tb_name //条件必须实现IEnumerable接口 //Linq to SQL,Linq to Xml ,Linq to DataSet,Linq to Objects int[] numbers = { 5, 10, 8, 3, 6, 12 }; //Query Systax var numQuery1 = from num in numbers where num % 2 == 0 orderby num select num; foreach (int num in numQuery1) { Console.WriteLine(num); } //method Systax var numQuery2 = numbers.Where(n => n % 2 == 0).OrderBy(n => n); foreach (int num in numQuery2) { Console.WriteLine(num); } Console.ReadLine();
语法
private static void QuerySysnax() { //1.datasource double[] numbers = { 110.00, 1, 2, 3, 4, 5, 6, 7 }; //2.query creation var numquery = from num in numbers where num % 2 == 0 select num; int numCount = numquery.Count(); //3.query execution Console.WriteLine("1234567890"); foreach (double num in numquery) { Console.WriteLine("{0,10}", num); } }
基本操作
from 获取数据源
where 过滤条件
order 排序
select 获取结果
group
group into打包(group 一起用)
join
let 中间变量
private static void myquery() { string[] mystrings = { "Hello qxw.", "This is Friday!", "Are you Happy?" }; var stringQuery = from s in mystrings let words = s.Split(‘ ‘) from word in words let w = word.ToUpper() select w; //var stringQuery = from s in mystrings // let w = s.ToUpper() // select w; foreach (var s in stringQuery) { Console.Write("{0} ", s); } }
标签:
原文地址:http://www.cnblogs.com/handsomer/p/4560985.html