文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>光脚丫学LINQ(013):LINQ查询语法与方法语法

光脚丫学LINQ(013):LINQ查询语法与方法语法

时间:2010-10-29  来源:光脚丫思考

static void Main(string[] args)   
{   
    int[] Numbers = { 5, 10, 8, 3, 6, 12 };   
  
    // Query syntax:   
    IEnumerable<int> NumQuery1 =   
        from num in Numbers   
        where num % 2 == 0   
        orderby num   
        select num;   
  
    // Method syntax:   
    IEnumerable<int> NumQuery2 =   
        Numbers.Where(num => num % 2 == 0).OrderBy(n => n);   
  
    foreach (int i in NumQuery1)   
    {   
        Console.Write(i + " ");   
    }   
    Console.WriteLine(Environment.NewLine);   
    foreach (int i in NumQuery2)   
    {   
        Console.Write(i + " ");   
    }   
  
    // Keep the console open in debug mode.   
    Console.WriteLine(Environment.NewLine);   
    Console.WriteLine("Press any key to exit");   
    Console.ReadKey();   
  
}  
static void Main(string[] args)
{
    int[] Numbers = { 5, 10, 8, 3, 6, 12 };

    // Query syntax:
    IEnumerable<int> NumQuery1 =
        from num in Numbers
        where num % 2 == 0
        orderby num
        select num;

    // Method syntax:
    IEnumerable<int> NumQuery2 =
        Numbers.Where(num => num % 2 == 0).OrderBy(n => n);

    foreach (int i in NumQuery1)
    {
        Console.Write(i + " ");
    }
    Console.WriteLine(Environment.NewLine);
    foreach (int i in NumQuery2)
    {
        Console.Write(i + " ");
    }

    // Keep the console open in debug mode.
    Console.WriteLine(Environment.NewLine);
    Console.WriteLine("Press any key to exit");
    Console.ReadKey();

} 


两个示例的输出是相同的。您可以看到两种形式的查询变量的类型是相同的:IEnumerable<T>。

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载