What is The Difference Between Capacity and Count Properties on List Types in C# and .NET?

Serkut Yıldırım
2 min readDec 17, 2023

--

List<T>.Capacity Property is used to gets or sets the total number of elements the internal data structure can hold without resizing.

List<T>.Count Property is the number of elements that are actually in the List<T>.

Figure 1–0–1

Capacity is the number of elements that the List<T> can store before resizing is required.But Count is the number of the elements which are actually present in the List.

Capacity is always greater than or equal to Count. If Count exceeds Capacity while adding elements, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new elements.

If the Capacity is settled explicitly then the internal array is also reallocated to accommodate the specified capacity, and all the elements are copied.

If the Capacity is much larger than the Count the user can decrease capacity or explicitly setting the Capacity to a lower value (see TrimExcess method).

Figure 1–0–2

Figure 1–0–2 shows us the return and exception types of the Capacity Property.

Figure 1–0–3

Count Property returns the number of items in System.Collections.Generic.List`1, as seen in figure 1–0–3.

--

--