zoukankan      html  css  js  c++  java
  • (转)C#中的Predicate<T>与Func<T, bool>

      Delegate至少0个参数,至多32个参数,可以无返回值,也可以指定返回值类型。这个是祖宗。
      Func可以接受0个至16个传入参数,必须具有返回值。
      Action可以接受0个至16个传入参数,无返回值。
      Predicate只能接受一个传入参数,返回值为bool类型。

    public delegate bool Predicate<in T>(T obj);  
    public delegate TResult Func<in T, out TResult>(T arg);  
    Func<T, bool> :表示有传入T类型的参数,返回值为bool的委托
    Predicate<T>:表示有传入T类型的参数,返回值为bool的委托
    static void Main(string[] args)  
    {  
        Predicate<int> myPredicate = i => i > 10;  
        Func<int, bool> myFunc = i => i > 10;  
        List<int> list = new List<int>();  
        list.Add(5);  
        list.Add(9);  
        list.Add(20);  
        list.Add(30);  
        List<int> newList = list.FindAll(myPredicate);  
        List<int> newListFunc = list.Where(myFunc).ToList();  
        Console.ReadKey();  
    } 
    看到Predicate和Func接受的是完全相同的Lambada表达式,
    而且执行结果newList和newListFunc完全相同。
     
    http://blog.csdn.net/rye_grass/article/details/66041423  C#中的Predicate<T>与Func<T, bool>
  • 相关阅读:
    Zepto swipe 无效(坑)
    Zepto.js-Ajax 请求
    Zepto.js-事件处理
    excel 大文件解析原理实现
    springboot 集成J2Cache
    springboot 单元测试 指定启动类
    springboot 解决 数字长度过长导致JS精度丢失问题
    JS 基本操作
    VUE 动态菜单管理
    VUE router-view key 属性解释
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/8227649.html
Copyright © 2011-2022 走看看