Convert Generic List to Array

Here is a method to convert a generic list to an Array.

public static T[] ConvertListToArray<T>(List<T> theList)
{
try
{
if (theList == null)
{
return null;
}

T[] theArray = new T[theList.Count];

for (int i = 0; i < theArray.Length; i++)
{
theArray[i] = theList[i];
}

return theArray;
}
catch (Exception ex)
{
throw ;
}
}

Advertisements

Got something to add?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s