When I first learnt about the ArrayList (about a week ago) I needed to
use it because I didn't know in advance the number of elements that I
wanted to store.
One other thing that struck me as useful with the arraylist was the
ability to store different types in the same arraylist. If you are
using a List<Tdoes this not preclude you from storing different
types in the list?
I am fairly new to programming but just thought that the ability to
store different types was kind of neat considering all the other
'stores' of data i've encountered allowed you to only store data of a
certain type.
Am i right in thinking this is a useful feature of the ArrayList or is
there a better way of storing different data types in one collection?
Well, I would question why you need this feature in the first place because
it might be indicitive of a weak design. But, if you really want it you can
just use List<object>. Then, you get all of the cool API features of List<T>
in weakly-typed collection.
Best Regards,
Dustin Campbell
Developer Express Inc.