Transform Array - CSharp System

CSharp examples for System:Array Create

Description

Transform Array

Demo Code


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

public class Main{
        public static TOutput[] TransformArray<TInput, TOutput>(this IEnumerable<TInput> enumerable,
                                                Func<TInput, TOutput> transformer)
      {
         var output = new TOutput[enumerable.Count()];

         var enumerator = enumerable.GetEnumerator();
         for (var i = 0; i < output.Length; i++)
         {
            enumerator.MoveNext();
            output[i] = transformer(enumerator.Current);
         }

         return output;
      }
}

Related Tutorials