/// <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<>居然沒(méi)有這個(gè)方法了,只好自己參考List<>.Find寫(xiě)了一個(gè).
Utils.Find(list, delegate(Test item){
return Item.Id == testId;
}
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄