Difference between an Array and ArrayList in dotnet framework
Loading
Difference between an Array and ArrayList in dotnet framework
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sangeetha SRank #212 · 11.4K reputationPosted Jun 10, 2025, 2:09 AM EDT
object)Listinstead)Listinstead)Vishal YelveRank #178 · 13.6K reputationPosted Jun 14, 2025, 2:30 PM EDT
ArrayArrayListobject)T[])Listinstead)Listinstead ofArrayListConceptual Differences
?? 1. Array
Declared with a specific type and fixed size.
Example:
int[] numbers = new int[3]; numbers[0] = 1; numbers[1] = 2;Benefits:
Type safety (compile-time checking).
Better performance for value types.
Limitations:
Size is fixed after creation.
Can't mix different data types.
2. ArrayList
Part of System.Collections (non-generic).
Stores elements as object, allowing mixed types (not recommended).
Example:
ArrayList list = new ArrayList(); list.Add(1); // boxed int list.Add("hello"); // stringDrawbacks:
Boxing/unboxing overhead with value types.
No compile-time type checking.
Example Comparison
// Array (strongly typed) int[] ages = new int[2]; ages[0] = 25; ages[1] = 30; // ArrayList (weakly typed) ArrayList data = new ArrayList(); data.Add(25); // boxed data.Add("John"); // allowed, but dangerous int age = (int)data[0]; // requires castingShould You Use
ArrayList?No — use
Listinstead (fromSystem.Collections.Generic).List list = new List(); list.Add(10); // no boxing int num = list[0]; // no casting neededIn Summary:
ArrayListArrayList(not recommended)