zoukankan      html  css  js  c++  java
  • 委托,Lambda的几种用法

    int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

    对此数组进行查询,查询小于5的数:

     方法1:( 使用查询表达式)

    var lowNus = from n in numbers where n < 5 select n;


    方法2 :var lowNus = numbers.Where(n => n < 5);
     
    方法3:var lowNus = numbers.Where(delegate(int n) { return n < 5; });

    方法4:

    Func<int, bool> ourfunc = delegate(int n) { return n < 5; };

    var lowNus = numbers.Where(ourfunc);

     
    方法5:

    Func<int, bool> myfunc = n => n < 5;

    var lowNus = numbers.Where(myfunc );


    方法6:

    Expression<Func<int, bool>> exp = n => n < 5;

    var lowNus = numbers.Where(exp.Compile());

     

    以上方法的输出结果:

    4,1,3,2,0

  • 相关阅读:
    053-242
    053-227
    053-671
    053-489
    053-670
    sql
    白纸黑字签字画押,出人命的事
    CSS
    JS
    Eclipse发布地址不同引发的问题
  • 原文地址:https://www.cnblogs.com/ycdx2001/p/1422478.html
Copyright © 2011-2022 走看看