IEnumerable没有一个ForEach方法,我们可以使用C#写一个扩展方法:
为IEnumerable扩展一个ForEach方法


Source Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Insus.NET.ExtendMethods
{
  public static class Enumerables
    {        
        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (T item in source)
            {
                action(item);
            }
        }
    }
}
View Code

相关文章:

  • 2021-11-29
  • 2021-12-18
  • 2022-01-25
  • 2022-12-23
  • 2021-09-10
  • 2021-12-15
  • 2022-12-23
  • 2021-11-15
猜你喜欢
  • 2021-08-22
  • 2022-01-23
  • 2021-09-04
  • 2022-12-23
  • 2021-11-29
  • 2022-03-03
  • 2021-05-18
相关资源
相似解决方案