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;

    }

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


  • 相关阅读:
    [bzoj1095] [ZJOI2007]Hide 捉迷藏
    [bzoj3730] 震波
    [bzoj3672] [Noi2014]购票
    [bzoj4129] Haruna’s Breakfast
    《CSS3知识点》
    《表单总结》
    <表格>
    《HTML总结》
    <java程序大集合>
    《字符串的概念》
  • 原文地址:https://www.cnblogs.com/nonlyli/p/1325859.html
Copyright © 2011-2022 走看看