Difference between Array and ArrayList
Difference between Array and ArrayList
211
13-Jun-2024
Updated on 13-Jun-2024
Ashutosh Kumar Verma
13-Jun-2024C# Array vs ArrayList
Arrays and ArrayLists are used to store aggregated data but have many differences in features and functionality
Syntax-
Array
ArrayList
There are several differences between Array and ArrayList as follows,
Type Safety
Resizing
Performance
Usage
Length Property vs. Count Property
Element Access
Example-
Array
Output-
ArrayList
Output-
In summary, Arrays work well and are suitable for fixed-size collections of known types, while ArrayLists offer flexibility and dynamic resizability, making them suitable for situations where collection size may change or where type flexibility is important However, with the introduction of generics in C# (e.g., List<T>), ArrayLists are rare in modern codebases.
Also, Read: Dictionary vs Hashtable in C#