LINQ---查询语法和方法语法
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 ); } } }