lamdba表达式ForEach扩展方法:
public static void GetForEach<T>(this IEnumerable<T> list, Action<T> action)
{
foreach (var da in list)
{
//输出
action(da);
}
}
2.lamdba表达式Where扩展方法:
public static IEnumerable<T> GetWhere<T>(this IEnumerable<T> list, Func<T, bool> action)
{
List<T> tlist = new List<T>();
foreach (var da in list)
{
Console.WriteLine(action(da));
if (action(da))
{
tlist.Add(da);
}
}
return tlist;
}
3.lamdba表达式FirstOrDefault扩展方法:
public static T GetFirstOrDefault<T>(this IEnumerable<T> list, Func<T, bool> func)
{
T t = default(T);
foreach (T da in list)
{
if (func(da))
{
return da;
}
}
return t;
}