For Each in IEnumerable by Action - CSharp System.Collections

CSharp examples for System.Collections:IEnumerable

Description

For Each in IEnumerable by Action

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*  w w w. j  a  v a 2 s  . c  o  m*/

public class Main{
        internal static void ForEach<T>(IEnumerable<T> collection, Action<T> action)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");
            if (action == null)
                throw new ArgumentNullException("action");

            foreach (T item in collection)
                action(item);
        }
}

Related Tutorials