Home
Manage Your Code
Snippet: Convert Generic Collection to Generic Array (C#)
Title: Convert Generic Collection to Generic Array Language: C#
Description: This method converts a generic collection to a generic array. Views: 912
Author: Dave Donaldson Date Added: 1/29/2007
Copy Code  
1public static T[] ToGenericArray<T>(Collection<T> collection)
2{
3    if (collection == null)
4    {
5        return new T[] { };
6    }
7
8    return new List<T>(collection).ToArray();
9}
Usage
// Assuming coll is a generic collection of type int
int[] arr = ToGenericArray(coll);