zoukankan      html  css  js  c++  java
  • LinQ In Action 学习第三章

    本章开始前先回顾一个小例子,复习一下第二章所讲内容

      var pc = Process.GetProcesses()
                    .Where(p => p.WorkingSet64 >= 20 * 1024 * 1024) // lamador expression
                    .OrderByDescending(p => p.WorkingSet64)// extension method
                    .Select(p => new { ID = p.Id, Name = p.ProcessName, Memory = p.WorkingSet64 });// Anymorous type and  object initiallizer
                Console.WriteLine(pc);
                Console.Read();

    开始第三章:

    第一个概念:了解 iterator 和return yeild 工作机制 和deferred query execution 延迟执行查询。

    通过一个例子可以看出来。

     static double Square(double n)
             {
                 Console.WriteLine("Computing Square(" + n + ")...");
                 return Math.Pow(n, 2);
             }

     int[] itegers = new int[] { 1, 3, 5 };
                
                var iv = itegers.Select(n => Square(n));
              
                foreach(var p in iv.ToList()){
                    Console.WriteLine( p);
                }
                Console.Read();

     static double Square(double n)
             {
                 Console.WriteLine("Computing Square(" + n + ")...");
                 return Math.Pow(n, 2);
             }

    int[] itegers = new int[] { 1, 3, 5 };
                
                var iv = itegers.Select(n => Square(n));
              
                foreach(var p in iv){
                    Console.WriteLine( p);
                }
                Console.Read();

    "Yeild" 机制非常重要使LINQ可以实现lazy execution。

    1. Lamador Expression

    2. Lamador Operator

    3. Lazy Executation iterator, return yeild

    4. Expression tree

    介绍了 Lamador Expression,Lamador Operator 以及他们俩之间的关系。  

    Lamador Operator will be compiled into Lamador Expression, 两者可以结合使用。例子就不写了很简单。

    表达式树不是很明白。 留下来有空在好好研究吧。

  • 相关阅读:
    ride.py 启动报错
    python中的__call__函数
    python-namedtuple命名元组
    python模块-操作excel(xlsxwriter)
    (转)python中@property详解
    python中使用logging将日志写入文件或输出到控制台
    “selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities“解决办法
    Fiddler对https抓包时,提示"HTTPS decryption is disabled."
    fiddler的使用
    常用软件激活/破解
  • 原文地址:https://www.cnblogs.com/recordlife/p/4217925.html
Copyright © 2011-2022 走看看