Transform List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Transform List

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;/*from   ww  w  .  j av  a 2s. c o m*/

public class Main{
        #endregion

      #region Transform
      public static List<TOutput> TransformList<TInput, TOutput>(this IEnumerable<TInput> enumerable,
                                                   Func<TInput, TOutput> transformer)
      {
         var output = new List<TOutput>(enumerable.Count());

         foreach (var input in enumerable)
         {
            output.Add(transformer(input));
         }

         return output;
      }
}

Related Tutorials