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);  
            }  
        }  
    }  
}  

相关文章:

  • 2022-03-03
  • 2021-10-02
  • 2021-07-14
  • 2021-11-04
  • 2022-01-31
  • 2022-12-23
  • 2021-09-08
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案