Reputation: 3869
Is there builtin method that would do this or do I always have to manually create a new array and then fill it up with a foreach loop
Upvotes: 14
Views: 32364
Reputation: 292355
List<int> list = ...
...
int[] array = list.ToArray();
You can also use the CopyTo method :
int[] array = new int[list.Count];
list.CopyTo(array);
Upvotes: 11