Junior Collections

What is the difference between List<T> and ArrayList in C#?

Feature List<T> ArrayList

Generic Yes No

Type Safety Compile-time Runtime (casting required)

Performanc

Better (no boxing) Slower for value types (boxing)

Follow:

Example:

List<int> list = new List<int>();

list.Add(10); // Type-safe

ArrayList arrayList = new ArrayList();

arrayList.Add(10);

int num = (int)arrayList[0]; // Casting required

Best Practice:

Always prefer List<T> in new code. Use ArrayList only when working with legacy

systems.

More from C# Programming Tutorial

All questions for this course