Default Capacity of List

What is the default capacity of a List?


Actually, it starts with a Capacity of 0. When you add the first element, the current implementation allocates a capacity of 4. After that, the capacity keeps doubling if expansion is needed, to guarantee amortized O(1) operation.

Keep in mind that this is the current behavior. You shouldn't rely on it to be the case. This should demonstrate the current behavior:

List<int> list = new List<int>();
int capacity = list.Capacity;
Console.WriteLine("Capacity: " + capacity);

for (int i = 0; i < 100000; i++)
{
    list.Add(i);
    if (list.Capacity > capacity)
    {
        capacity = list.Capacity;
        Console.WriteLine("Capacity: " + capacity);
    }
}

Why don't you just try it?

Console.WriteLine("Default capacity of a List: " + new List<int>().Capacity);

This answer will work on all versions of .NET that have List. On my version, it happens to be 0.


According to the sample on the MSDN parameterless constructor documentation, the initial capacity of a list created with:

List<string> x = new List<string>();

is 0. As far as I can tell, this isn't documented as a guarantee, nor is the resize policy documented (i.e. it may currently double with a minimum of 4, but in .NET 5.0 it could triple with a minimum of 128.) You shouldn't rely on this behaviour, basically.