Difference between Areay and ArrayList in DotnetFramework
Loading
Difference between Areay and ArrayList in DotnetFramework
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
Baibhav KumarRank #64 · 26.5K reputationPosted May 22, 2025, 12:19 AM EDT
Array
ArrayList
int) because of type conversions.Sandhiya PriyaRank #26 · 43.2K reputationPosted Jan 1, 2026, 2:05 AM EST
ArrayvsArrayListin .NET Framework. Let’s break it down carefully and clearly, because they look similar but behave very differently.1. Array
Definition: A fixed-size, strongly typed collection of elements.
Namespace:
SystemSyntax Example:
int[] numbers = new int[5]; // Array of 5 integers numbers[0] = 10;Characteristics:
Fixed Size – once created, you cannot change the size.
Strongly Typed – all elements must be of the same type (
int,string, etc.).Performance – faster because it’s a simple, contiguous block of memory.
Index-based – access elements using an index:
numbers[0].2. ArrayList
Definition: A dynamic, non-generic collection of objects.
Namespace:
System.CollectionsSyntax Example:
ArrayList list = new ArrayList(); list.Add(10); // int list.Add("Hello"); // stringCharacteristics:
Dynamic Size – you can add or remove elements anytime.
Holds objects of any type – but you lose type safety (you need casting when retrieving values).
int num = (int)list[0]; // must castSlower than Array – because elements are stored as objects and boxing/unboxing may occur for value types.
Index-based – like arrays, you can access elements with an index.
3. Key Differences Table
Note
In modern .NET development, instead of
ArrayList, people usually useList(fromSystem.Collections.Generic) because it’s type-safe and dynamic, combining the best of both worlds.Example:
List list = new List(); list.Add(10); list.Add(20);Sarthak VarshneyRank #46 · 32K reputationPosted May 22, 2025, 12:13 AM EDT
int[],string[])object)Listfor generics)int[]stores actual ints)intis boxed toobject)Listis not usedExample:
Array:
ArrayList:
ArrayList list = new ArrayList(); list.Add(1); // Value type (int) will be boxed list.Add("hello"); // Stores different types (not type-safe)Recommendation:
Arrayfor performance-critical, fixed-size, type-safe scenarios.List(fromSystem.Collections.Generic) instead ofArrayListin modern .NET for better type safety and performance.Let me know if you want a comparison including
Listtoo!Sam HobbsRank #107 · 20.5K reputationPosted Jan 1, 2026, 3:04 PM EST
A simple explanation is that Array is part of the C# language; it is in the System namespace. ArrayList is in the System.Collections namespace. When possible it is better to use the List class in the System.Collections.Generic namespace. It can be used very much like an ArrayList but has the advantage of type safety.