Mega Code Archive

 
Categories / C# / Collections Data Structure
 

ConvertAll ICollectionTIn to TOut[] with ConverterTIn, TOut

using System; using System.Collections.Generic; using System.Collections;   public static class CollectionUtils   {     public static TOut[] ConvertAll<TIn, TOut>(this ICollection<TIn> collection,       Converter<TIn, TOut> converter)     {       TOut[] res = new TOut[collection.Count];       int i = 0;       foreach (TIn elem in collection)       {         res[i] = converter(elem);         i++;       }       return res;     }   }