Select a result to preview
List<T> is the default dynamic array in .NET. Use it when you need ordered data, fast index access, and efficient appends.
List<T> stores items in a contiguous array, so indexing by position is O(1) and iterating is cache friendly.
When Count grows past Capacity, the internal array is reallocated and copied to a larger buffer.
When Count exceeds Capacity, List<T> allocates a new internal array with double the current capacity (power-of-two growth), copies all elements, and releases the old buffer. The doubling strategy ensures any sequence of n appends costs O(n) total — amortized O(1) per append — even though individual resize events are O(n). The pre-sizing constructor new List<T>(capacity) eliminates resizes for known-size collections, which matters in hot paths where repeated allocation and GC pressure are measurable. Prefer Capacity pre-sizing over post-construction TrimExcess when the final size is known upfront.
graph LR
I0[index zero ann] --> I1[index one bob] --> I2[index two chris]var users = new List<string>(capacity: 4) { "Ann", "Bob" };
users.Add("Chris");
users.Remove("Bob");
// O(1) index access
Console.WriteLine(users[0]);
Clear() resets Count but usually keeps Capacity.List<T> over LinkedList<T> for most workloads because iteration is faster in practice.LinkedList<T> only when you already hold node references and need O(1) inserts/removes around them.List<T> implemented under the hood?
List<T> wraps an internal T[] buffer and tracks Count separately from Capacity.
When capacity is exceeded, it allocates a bigger array and copies elements.
Count and Capacity in List<T>?
Count is the number of logical elements. Capacity is the size of the internal array.
Clear() and Remove() affect Capacity in List<T>?
They usually change only Count. To shrink memory, use TrimExcess() or set Capacity.
List<T> replaces ArrayList and when to prefer other collection types.
Parent
02 Computer Science
Pages