> Note that although ArrayList is perfectly valid in .NET 1.1, it is not
> an ideal choice if you are using .NET 2.0 or above (where List<T>
> would be far preferable). At the minimum it will save you from a lot
> of casting. More likely it will save a good number of daft bugs.
I'm not sure about actually quashing bugs - not in and of itself.
How many times have you *actually* had an InvalidCastException when
fetching something from an ArrayList? It's more of a theoretical
problem than a real one, IMO.
However, it does make the code less readable and less self-documenting
- and *that* could cause bugs.
Another reason for using List<T> instead of ArrayList: the non-generic
collections aren't going to be available in Silverlight 2.0. Unlikely
to affect the OP, admittedly...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Marc Gravell - 11 Mar 2008 16:45 GMT
> How many times have you *actually* had an InvalidCastException...
Not very many at all. But I do recall one such (back in the day) where
a Sort was barfing horribly; it was a really stupid and pointless bug,
and took 2 seconds to fix (IIRC it was a list being needlessly re-used
for different contents, and one code-path failing to Clear() it
first), but it took quite a bit longer to *find* the underlying cause.
Just the mentality of "it's object, I can use anything" breeds
unnecessary potential for error.
> Another reason for using List<T> instead of ArrayList: the non-generic
> collections aren't going to be available in Silverlight 2.0.
Yeah - I heard they had to be pretty brutal about what got included...
same between XmlDocument and XDocument IIRC... (from passing
conversations - I haven't looked myself).
Marc
Michael Nemtsev [MVP] - 11 Mar 2008 22:19 GMT
Hello Jon Skeet [C# MVP],
J> Another reason for using List<T> instead of ArrayList: the
J> non-generic collections aren't going to be available in Silverlight
J> 2.0. Unlikely to affect the OP, admittedly...
it's not actually only Silverlight 2.0.
MS announced that they won't include non-generic to the new developed libraries
and technologies.
so, I'd say if u are not using generics today, tomorrow u gonna port all
your apps to generics
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
I had looked at both after I posted the response, I quickly
realized that I need to use List<T> and not arrayList.
According to the description I can access the list by
index, insert to and delete from the list. That is just
what I need.
I am searching for some good tutorials on the topic now.
> Note that although ArrayList is perfectly valid in .NET 1.1, it is not
> an ideal choice if you are using .NET 2.0 or above (where List<T>
> would be far preferable). At the minimum it will save you from a lot
> of casting. More likely it will save a good number of daft bugs.
>
> Marc