469,299 Members | 2,073 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

ArrayList Class Vs. List Generic Class

Hello,

I need an array of objects. I am considering using either ArrayList Class
or List Generic Class.

Any guidelins regarding when to use one or the other?

Thanks
Eitan
Jun 15 '07 #1
3 6629
Eitan,

The only reason I can see using an ArrayList is when all the values that
you are going to store do not have a common base class (other than object).
However, in this case, I would suggest using List<object>, as List<object>
supports the IList<Tinterface still.

If the types that you are going to store in the list are all of the same
type, then use the generic class. In most instances (especially when
storing value types, because there is no boxing) you will see a performance
gain over the ArrayList class (even with reference types, there is a slight
performance gain).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
Hello,

I need an array of objects. I am considering using either ArrayList Class
or List Generic Class.

Any guidelins regarding when to use one or the other?

Thanks
Eitan

Jun 15 '07 #2
ArrayList have some *build-in* methods/properties like SyncRoot or
Synchronized(ArrayList/IList) that can be
helpful for the thread sync. if needed. I don't think that generic List have
that.

"Eitan" <Ei***@discussions.microsoft.comwrote in message
news:39**********************************@microsof t.com...
Hello,

I need an array of objects. I am considering using either ArrayList Class
or List Generic Class.

Any guidelins regarding when to use one or the other?

Thanks
Eitan

Jun 15 '07 #3
Daniel Cigic <da**********@gmail.comwrote:
ArrayList have some *build-in* methods/properties like SyncRoot or
Synchronized(ArrayList/IList) that can be
helpful for the thread sync. if needed. I don't think that generic List have
that.
No, although there's SynchronizedCollection<T>.

Personally I dislike using the "synchronized" version of ArrayList as
it gives a false impression of automatic thread safety. You still need
to manually lock when you need to do anything which comprises more than
one operation, eg iterating through a list.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Sam | last post: by
48 posts views Thread by Alex Chudnovsky | last post: by
8 posts views Thread by | last post: by
28 posts views Thread by wanwan | last post: by
44 posts views Thread by Zytan | last post: by
8 posts views Thread by stainless | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.