C# Interview Question #35

What is List<T> in C#?

Generics & Collections Mid-Level Intermediate

Quick Interview Answer

List<T> is a generic, dynamically sized collection that stores elements of a specified type. It preserves insertion order and supports indexed access.

Detailed Explanation

List<T> is a generic, dynamically sized collection that stores elements of a specified type. It preserves insertion order and supports indexed access.

It provides methods such as Add, AddRange, Remove, RemoveAt, Contains, Find, FindAll, and Sort.

List<T> is one of the most commonly used collections when an application needs an ordered group whose size can change.

Code Example

List<string> products = new()
{
    "Laptop",
    "Mouse",
    "Keyboard"
};

products.Add("Monitor");

string first = products[0];