using System; using System.Linq; namespace LINQ语法实现 { class Program { static void Main(string[] args) { int[] a = { 3,1,2,4}; //1.Query syntax var Query1 = from num in a where num % 2 == 0 orderby num select num; foreach (var i in Query1) { Console.WriteLine("{0}", i); } Console.WriteLine(); //2.Method syntax var Query2 = a.Where(n => n % 2 == 0).OrderBy(n => n); foreach (var j in Query2) { Console.WriteLine("{0}", j); } } } }
时间: 2024-10-17 10:13:45