List<> Capacity returns more items than added
c#, collections, list
Solution
The `Capacity` of the list represents how much memory the list currently has set aside for the current objects and objects to be added to it. The `Count` of the list is how many items have actually been added to the list.
Problem
There are several properties on `List<T>` that seem to be related to number of items in the list - `Capacity`, `Count` (which is present as a property and a method). This is quite confusing especially compared with `Array` that has just `Length`. I'm using `List.Capacity` but it gives unexpected result: ``` List <string> fruits = new List<string>(); fruits.Add("apple"); fruits.Add("orange"); fruits.Add("banana"); fruits.Add("cherry"); fruits.Add("mango"); Console.WriteLine("the List has {0} items in it.", fruits.Capacity); ``` when I run this the Console displays: ``` the List has 4 items in it. ``` I don't understand why its showing a `Capacity` of 8, when I only added 5 items.