IEnumrable Foreach方法扩展


        public static IEnumerable<T> ForEach<T>(this  IEnumerable<T> source, Action<T> action) where T : class,new()
        {
            foreach (var item in source)
            {
                action(item);
                yield return item;
            }
        }

 

        public static void ForEach<T>(this  IEnumerable<T> source, Action<T> action) where T : class,new()
        {
            foreach (var item in source)
            {
                action(item);
            }
        }

 

 

你可能感兴趣的:(foreach)