namespace ConsoleApplication45 { class Program { static void Main(string[] args) { int[] numbers = { 2, 5, 28, 31, 17, 16, 42 }; var numsQuery = from n in numbers //查询语法 where n < 20 select n; var numsMethod = numbers.Where(x => x < 20); //发放查询 int numsCount = (from n in numbers //两种形式组合 where n < 20 select n).Count(); foreach (var x in numsQuery ) { Console.Write("{0} ", x); } Console.WriteLine(); foreach (var x in numsMethod ) { Console.Write("{0} ", x ); } Console.WriteLine(); Console.WriteLine("{0}", numsCount ); } } }
LINQ---查询语法和方法语法
猜你喜欢
转载自www.cnblogs.com/bedfly/p/11960595.html
今日推荐
周排行