The List<T> collection
The List<T>
generic class represents a collection of elements that can be accessed by their index. List<T>
is very similar to arrays, except that the size of the collection is not fixed but variable, and it can grow or decrease as elements are added or removed. In fact, the implementation of List<T>
uses an array to store the elements. When the number of elements exceeds the size of the array, a new and larger array is allocated, and the content of the previous array is copied to the new one. This means that List<T>
stores the elements in contiguous memory locations. However, for value types, these locations contain the values, but for reference types, they contain references to the actual objects. Multiple references to the same object can be added to a list.
The List<T>
class implements a series of generic and non-generic interfaces, as shown in the following declaration of the class:
public class List<T> : ICollection...