Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

[.net] [C#] ArrayList/List?

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking for something similiar to a C++ std::vector. I know in the past, I've used ArrayList. What's the difference between an ArrayList and a List? Are there any other containers I should know about?

Share this post


Link to post
Share on other sites
Advertisement
ArrayList existed before generics allowed for properly 'templated' containers.
HashTable -> Dictionary<K,V> is the same thing.

To my knowledge, there is no benefit to continued use of the untyped collections.

Share this post


Link to post
Share on other sites
For the most part the generic template containers are better than the untyped containers.

Here are the generics that you should know about:

List
Dictionary
Stack

Here are a few more:

LinkedList
SortedDictionary
Queue

Generic containers basically make it easier for the compiler to provide better code, and they make it easier for you not needing to type in castes and write wrappers all the time.

Don't dismiss the use of the old containers entirely though. They still have utility in some scenarios.

Share this post


Link to post
Share on other sites
Generics avoid the need for boxing/unboxing, which costs, so unless you're using a collection of different types in the same list there's no need to not use generics, however, I'm not certain how derived objects are handled, whether they're boxed or not, so if you have a collection based on a shared base class whether this has as much penalty as just using a none generic collection I don't know.

Share this post


Link to post
Share on other sites
Quote:
Original post by Niksan
Generics avoid the need for boxing/unboxing, which costs, so unless you're using a collection of different types in the same list there's no need to not use generics, however, I'm not certain how derived objects are handled, whether they're boxed or not, so if you have a collection based on a shared base class whether this has as much penalty as just using a none generic collection I don't know.
Boxing only happens when you're storing a value type as an object. Using List<object> is essentially the same as using ArrayList from a boxing perspective.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!