0
Can you initialize an array without specifying size ?
7 Respostas
+ 1
k.
+ 1
In a list you do not need to predefine the size, you just can add to is. Do you know yhe size on initialisation ?
list<int> mylist = new list <int>;
https://www.dotnetperls.com/list
+ 1
I meant it is known then ( when you use it ). It is of course runtime allocation.
0
Can you use a list ?
0
yes. since its size is predefined
0
True
0
Definitely use a List<T> any time you want to add/remove data, since resizing arrays is expensive. If you know the data is fixed length, and you want to micro-optimise for some very specific reason (after benchmarking), then an array may be useful.
List<T> offers a lot more functionality than an array (although LINQ evens it up a bit), and is almost always the right choice.
More on C# List : http://csharp.net-informations.com/collection/list.htm