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

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.