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?

Recommended Answers

All 3 Replies

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.

commented: Cheers +2

Note that ToList is a LINQ extension method, so apply references and usings appropriately.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.