LINQ语句的两种语法实现方式

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);  
            }  
        }  
    }  
}  
JAVA&NET技术QQ群号:456257217有问题的可以在群里面提问。
原文地址:https://www.cnblogs.com/shiyh/p/14930606.html