/// <summary>
/// 逐个对象执行predicate并获得返回值
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <param name="source"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public static IEnumerable<TSource> Each<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource> predicate)
{
foreach(TSource t in source)
{
yield return predicate(t);
}
}
IEnumerable<int> arr= new int[] { 1, 2, 3, 4 }.Each(info => info = info + 10);
运行结果:arr=new int[] { 11, 12, 13, 14 }