KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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.
Tags (comma-separated)
Save Edits
Cancel