Loading
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
Toufik El AzzaouiRank #3,804 · 389 reputationPosted Oct 11, 2022, 4:52 AM EDT
ArrayList is a non-generic collection class and is in the System.Collection namespace.
In the example above, we create an ArrayList object and add different data types to it. But in reality, ArrayList is a collection of type Object, and when we add an item to ArrayList, it first converts it to type Object, and then adds it to the collection.
Array is a sequential collection of elements with the same data type that are accessible via an index. the elements get stored in a contiguous memory location.
Differences between Array and ArrayList :
- Memory:
For Array the size is fixed.
For ArrayList the size is variable.
- Namespace:
For Array : System.Array
For ArrayList: System.Collection
- Data Type:
In Arrays, we can store only one datatype either int, string, char etc.
In ArrayList we can store different datatype variables.
- Null :
Array does not accept null.
ArrayList accepts null.
Please refer to this link for more information:
https://www.c-sharpcorner.com/article/difference-between-array-and-arraylist-in-c-sharp/
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 11, 2022, 5:00 AM EDT
1) Array belongs to the System namespace while ArrayList belongs to the System.Collections namespace.
2) An Array is strongly-typed so we can store only a similar type of data. While ArrayList is a non-generic collection type so we can store different types of data in ArrayList.
3) An array is a fixed size so it can store only a fixed number of elements. On the other hand, ArrayList is dynamic in terms of capacity, ArrayList will increase to double its current size if the number of elements exceeds.
4) We cannot insert any item in the middle of the array but we can insert an item in the middle of ArrayList.
5) We cannot delete any item from the middle of the array but we can remove an item from the middle of ArrayList.
6) Array provides better performance than ArrayList because it does not cause boxing and unboxing. But ArrayList involves boxing and unboxing.
7) The Array cannot accept null values while An ArrayList can accept null.
8) The array uses static helper class Array which provides support for handling the array but ArrayList implements an IList interface which provides different methods that are used for easy implementation.
https://www.c-sharpcorner.com/article/difference-between-array-and-arraylist-in-c-sharp/
https://www.c-sharpcorner.com/blogs/difference-between-array-and-arraylist-in-c-sharp
Vishal YelveRank #178 · 13.6K reputationPosted Oct 11, 2022, 5:41 AM EDT
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Oct 12, 2022, 5:50 AM EDT
The array is a specified-length data structure whereas ArrayList is a variable-length Collection class.
Array is strongly typed. This means that an array can store only specific type of items\elements whereas ArrayList can store any type of items\elements.
Examples:
int[] arr = new int[5]; // fixed length ArrayList arList = new ArrayList(); // Variable-length, you can add dynamically with add methodBrahma Prakash ShuklaRank #633 · 3.8K reputationPosted Nov 1, 2022, 4:26 AM EDT
An array can store primitive data as well as objects, but it cannot store generics. ArrayList is able to store generics as well as objects, but it cannot store data of primitive types