List<T> behind the scene.
when you create a new instance of List<T>, the list is
initially empty and has a capacity of zero, This means
that the internal array used to store the elements has
not been allocated yet. The capacity of the list is the
number of elements that the list can currently hold
without needing to resize the internal array.
When you add the first element to the list using
the Add method, the capacity of the list is increased to
the default capacity, which is 4. This means that the
internal array is allocated with a length of 4 and the
first element is added to the array, If you add more
elements to the list and the capacity is reached, the
internal array is automatically resized to twice its
current length to accommodate the new elements.
For example, if you add the fifth element to the list,
the capacity will be increased to 8, then to 16 if you add
the ninth element, and so on.
#lists #arrays #allocation #generic
@code_crafters
  when you create a new instance of List<T>, the list is
initially empty and has a capacity of zero, This means
that the internal array used to store the elements has
not been allocated yet. The capacity of the list is the
number of elements that the list can currently hold
without needing to resize the internal array.
When you add the first element to the list using
the Add method, the capacity of the list is increased to
the default capacity, which is 4. This means that the
internal array is allocated with a length of 4 and the
first element is added to the array, If you add more
elements to the list and the capacity is reached, the
internal array is automatically resized to twice its
current length to accommodate the new elements.
For example, if you add the fifth element to the list,
the capacity will be increased to 8, then to 16 if you add
the ninth element, and so on.
#lists #arrays #allocation #generic
@code_crafters