zoukankan      html  css  js  c++  java
  • IList<>添加Find(delegate)方法

            /// <summary>
            
    /// Find data in IList<T>
            
    /// </summary>
            public static T Find<T>(System.Collections.Generic.IList<T> list, Predicate<T> match)
            {
                
    if (list != null && list.Count > 0)
                {
                    
    foreach (T obj in list)
                    {
                        
    if (match(obj))
                        {
                            
    return obj;
                        }
                    }
                }

                
    return default(T);
            }

    IList<>居然没有这个方法了,只好自己参考List<>.Find写了一个.

    Utils.Find(list, delegate(Test item){

      return Item.Id == testId;

    }

    泛型上还有很多值得学的地方啊,但觉得现在代码越这样写就越不容易理解了,不知是不是合适.


  • 相关阅读:
    2017.8.07
    2017.8.05
    2017.8.04
    2017.8.03
    2017.8.02
    2017.8.01
    2017.7.31
    2017.7.29
    2017.7.28
    简易日历
  • 原文地址:https://www.cnblogs.com/nonlyli/p/1325859.html
Copyright © 2011-2022 走看看