Perform a specified action on every element of an collection. - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

Perform a specified action on every element of an collection.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//www.j a v a 2 s  . c  om

public class Main{
        /// <summary>
      /// Perform a specified action on every element of an collection.
      /// <param name="source">An IEnumerable&lt;T&gt; collection in which the iteration is performed.</param>
      /// <param name="func">The action to be performed.</param>
      /// </summary>
      public static void ForEach<T>(this IEnumerable<T> source, Action<T> func)
      {
         foreach (T elem in source)
         {
            func(elem);
         }
      }
}

Related Tutorials