C# Interview Question #34

What is the difference between an array and List<T>?

Generics & Collections Mid-Level Intermediate

Quick Interview Answer

An array has a fixed length after creation, while List<T> is a dynamically sized generic collection.

Detailed Explanation

An array has a fixed length after creation, while List<T> is a dynamically sized generic collection.

Arrays provide direct indexed access and are appropriate when the number of elements is known or fixed. List<T> provides convenient methods such as Add, Remove, RemoveAt, Contains, and Find, and automatically manages its internal capacity.

Both provide fast indexed access, but List<T> is generally more convenient when the collection size changes during application execution.

Code Example

int[] numbers = new int[3];
numbers[0] = 10;

List<int> values = new();
values.Add(10);
values.Add(20);
values.Remove(10);