范文 |
/// <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; } |