A Question about List

I am learning about using List function by analyzing someone else’s code. In the following code example:

items = new List.<Item>(n);

Should the List.Count function be equal to 10 if n = 10??

I’m getting a zero for List.Count but if that is so, why have n in the constructor?

Thanks for any clarity on this.

Mitch

n is the caching size (how many elements to precreate), but without adding anything to the list its number of elements (-> Count) will remain 0

You can look at microsofts MSDN for the documentation of List<> in System.Collections.Generic

If you know you’re going to need at least 10 elements, you should use (10). It’s faster than growing the array by one each time you add something, since the memory is already allocated. The .Count won’t change until you actually add something.

–Eric

Thanks guys - I did look at the MSDN docs but you guys explained it with more clarity. Appreciate it.