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)
Example:
List<int> list = new List<int>();
list.Add(10); // Type-safe
rrayList arrayList = new ArrayList();
rrayList.Add(10);
int num = (int)arrayList[0]; // Casting required
Best Practice:
lways prefer List<T> in new code. Use ArrayList only when working with legacy
systems.