Executes a function on each item in ICollection and returns the results in a new IList. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Executes a function on each item in ICollection and returns the results in a new IList.

Demo Code

// The contents of this file are subject to the Lesser GNU Public License (LGPL)
using System.Collections;

public class Main{

        /// <summary>
        /// Executes a function on each item in a <see cref="ICollection" />
        /// and returns the results in a new <see cref="IList" />.
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        public static IList Transform(ICollection coll, GenericMethod<object> func)
        {// w w  w. j a  v  a2  s  .  c om
            IList result = new ArrayList();
            foreach (object obj in coll)
                result.Add(func(obj));
            return result;
        }
}

Related Tutorials