C# Array vs ArrayList: Key Differences & When to Use Each
C# Array is a fixed-size, strongly-typed collection of elements; ArrayList is a resizable, non-generic list that stores everything as object, sacrificing type safety for flexibility.
Picture a parking garage: an Array is a numbered row of identical compact-car slots—fast to reach, no surprises. An ArrayList is a valet lot that accepts motorcycles, trucks, and even kayaks, but every time you fetch your vehicle you’re handed a generic ticket you must cast back to your actual ride.
Key Differences
Array: type-safe at compile time, contiguous memory, faster index access, cannot grow. ArrayList: stores objects, incurs boxing/unboxing overhead, grows automatically, accepts mixed types, throws runtime casting errors.
Which One Should You Choose?
Use Array when you know the exact count and type—pixel buffers, game loops. Choose ArrayList only in legacy .NET 1.x code or quick scripting; prefer List
Examples and Daily Life
Storing daily temperatures for a week? `double[] temps = new double[7];` works perfectly. Collecting survey answers where some are numbers, some text? `ArrayList answers = new ArrayList(); answers.Add(42); answers.Add(“yes”);`
Can ArrayList hold value types efficiently?
Yes, but every `int` is boxed into an object, causing GC pressure; prefer `List
Is Array ever resizable?
No; use `Array.Resize`, which creates a new Array and copies data.
When would legacy code still use ArrayList?
If you maintain pre-.NET 2.0 libraries or COM interop, ArrayList may remain unavoidable.