List<> capacity has more items than added.

Posted by Pete on Stack Overflow See other posts from Stack Overflow or by Pete
Published on 2010-03-20T23:04:01Z Indexed on 2010/03/20 23:11 UTC
Read the original article Hit count: 974

Filed under:
|
|
    List <string> ali = new List<string>();
    ali.Clear();
    ali.Add("apple");
    ali.Add("orange");
    ali.Add("banana");
    ali.Add("cherry");
    ali.Add("mango");
    ali.Add("plum");
    ali.Add("jackfruit");

Console.WriteLine("the List has {0} items in it.",ali.Capacity.ToString());

when I run this the Console displays:

the List has 8 items in it.

I don't understand why its showing a capacity of 8, when I only added 7 items.

© Stack Overflow or respective owner

Related posts about c#

Related posts about list