Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Convert ICollectionT to T[]

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