I have a few general questions about the Collections class in C#:"

  1. Because all elements in an ArrayList are stored as objects do we need to cast them into their respective types before extracting?

  2. Array lists are used if the size is adjusted accordinly to elements added and the types do not need to be defined, is this the only advantage over standard arrays? if not then what are some other advantages?

  3. Apart from the reason for not knowing the size or types of data to be added, when would we use array lists over standard arrays?

Thankyou for you time

2 Years
Discussion Span
Last Post by tinstaafl

These are some differences between the two:

•Arrays are strongly typed.
•ArrayLists are not strongly typed.

•Elements in Arrays have to be of same data type (int, string, double, char, bool…).
•Elements in an ArrayList can have a combination of combined data types or a single data type. Note: If an Array-List has combined data types then a type cast is a must.

•Arrays are of fixed specified length size therefore they cannot be resized dynamically during runtime.
•ArrayList can resize dynamically during runtime.

Edited by ddanbe: Typos


Generally you'll find that ArrayList are largely deprecated as List<>'s are at least as easy to use as well as being strongly typed.

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.