0

I know that the main difference between an array and a list is that a list size changes dynamically as items are added or removed. Because of this, if we copy an array to a list does that mean that the list must have a static size of the array's capacity?

3
Contributors
3
Replies
23
Views
3 Years
Discussion Span
Last Post by deceptikon
1

All you need to do is pass the array as a parameter in the List's new constructor or use the ToList() method and assign it to the list:

long[] test = new long[20];
List<long> testlist1 = new List<long>(test);
List<long> testlist2 = test.ToList();

Once the list is initiated the size is still dynamic and you can add/remove items.

Edited by tinstaafl

Votes + Comments
Cheers
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.