zoukankan      html  css  js  c++  java
  • System.Linq扩张方法Where (Lambda表达式)

    简单的 Where,实现可能如下:
    public static List<T> Where (this List<T> list,委托 delegate)
    {
         List<T>  tmpList = new List<T> ();
         foreach( T p in list){
            if(delegate(p)){   
              tmpList.add(p);
             }
        }
         return tmpList;
     }

    List<Person> persons = new List<Person> {"sds","sdsd"};

    下面分别使用Lambda表达式和匿名方法
    List<Person>  tmp = persons.Where(p=>p.Name =="sds");
    等于List<Person>  tmp = persons.Where((Person p)=>p.Name =="sds"); //编译器
    还等于List<Person>  tmp = persons.Where(Delegate(Person p) {
                                                                           return p.Name =="sds";
                                                                       })

    不过linq to object采用的是延迟查询;在看下面一例:
      static void Main(string[] args)
      {
        var ints = new int[] { 1, 2, 3, 4, 5, 6 };
        IEnumerable<int>  q = from i in ints select i;

       foreach(............)
      }
      此时的q并未返回查询的结果,而是返回一个IEnumerable<int>,以使foreach可以工作;

    这里有准确的说法:http://blog.joycode.com/scottgu/archive/2007/04/09/100744.aspx
  • 相关阅读:
    Easy Install详细参数
    linux.backspace乱码(转)
    RemoteFX
    netsh
    sc.exe
    WinRM和WinRS
    安全配置向导
    使用 Sconfig.cmd 配置服务器核心服务器
    FSMO
    Windows Server 2012之活动目录域服务的卸载
  • 原文地址:https://www.cnblogs.com/pojia/p/1125725.html
Copyright © 2011-2022 走看看