This post will discuss how to convert a list to an array in C#.

C# supports straight conversion from a List<T> to an array T[] using the List<T>.ToArray() method. It returns an array containing copies of all the list elements. The following example demonstrates usage of the ToArray() method:

Download  Run Code

 
To convert a list of one type to an array of another type, you can apply a transform function to each list element before invoking the List<T>.ToArray() method. This can be easily done using the Enumerable.Select() method, which projects each element of a sequence into a new form. The following example demonstrates this:

Download  Run Code

 
If you don’t prefer LINQ, you can use the List<T>.ConvertAll() method to convert a list of one type to a list of another type.

Download  Run Code

That’s all about converting a list to an array in C#.