- According to this question the default capacity set to
new List<int>;
is 0 and afterAdd(3);
it's 4. - The capacity set to
new List<int>(5);
should be 5 because the capacity is set via the parameter. - However what's the capacity set to
new List<int>() {3,5};
? 4 or 2 ?- It should be 4 if it behaves like in 1. above: the two initialization values in
{3, 5}
are added with two consecutiveAdd()
operations so that the capacity is still 4 because the two values did not overflow this capacity. - Or is it set to 2 by the Compiler because it recogizes the two values, 3 and 5 that are added to the List, counts them and sets this number as the capacity ?
- It should be 4 if it behaves like in 1. above: the two initialization values in
This question matters in regards to the garbage collector performance as desribed in this blog.