zoukankan      html  css  js  c++  java
  • 泛型委托

    1.Action<T> 泛型委托

       有参数,无返回值 。

       public delegate void Action<T>(T obj)


    public void ForEach(Action<T> action)
    {
        
    if (action == null)
        {
            ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
        }
        
    for (int i = 0; i < this._size; i++)
        {
            action(
    this._items[i]);
        }
    }

     

    2. Func<T,TResult> 泛型委托
      
    有参数,也可没有参数,一定有返回值。

      public delegate TResult Func<T,TResult>(T arg)


    public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
    {
        
    if (source == null)
        {
            
    throw Error.ArgumentNull("source");
        }
        
    if (predicate == null)
        {
            
    throw Error.ArgumentNull("predicate");
        }
        
    if (source is Iterator<TSource>)
        {
            
    return ((Iterator<TSource>) source).Where(predicate);
        }
        
    if (source is TSource[])
        {
            
    return new WhereArrayIterator<TSource>((TSource[]) source, predicate);
        }
        
    if (source is List<TSource>)
        {
            
    return new WhereListIterator<TSource>((List<TSource>) source, predicate);
        }
        
    return new WhereEnumerableIterator<TSource>(source, predicate);
    }

     

     

    3.Predicate<T> 泛型委托 
      表示定义一组条件并确定指定对象是否符合这些条件的方法.

      public delegate bool Predicate<T>(T obj) 

    Predicate在List Find()中的使用
  • 相关阅读:
    ASP.NET解决Sqlite日期类型问题:该字符串未被识别为有效的 DateTime
    无法定位程序输入点_except_handler4_common于动态链接库msvcrt.dll上
    无意中找到的一个“通用不间断滚动JS封装类”
    sqlite中字符串的连接操作
    dhtmlxTree介绍
    项目之小模块有感
    JAVA中创建对象的四种方式
    Eclipse插件汇集(未完善)
    apache之beanutils包比较工具类ComparatorUtils
    Eclipse之maven插件m2eclips
  • 原文地址:https://www.cnblogs.com/ycdx2001/p/1518432.html
Copyright © 2011-2022 走看看