?
Solved

System.Collections.Generic.Dictionary vs System.Collections.Generic.List

Posted on 2011-10-03
3
Medium Priority
?
356 Views
Last Modified: 2013-12-16
Is there any buddy you help me out. i am trying looking about the which i more efficient or fast between these 2 System.Collections.Generic.Dictionary vs System.Collections.Generic.List
0
Comment
Question by:sachin233
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1500 total points
ID: 36907446
The only way know which is faster between 2 different type of objects is to test both.

There are too many variables. Maybe a Dictionary of Strings will be faster than a List of Strings, but a Dictionary of Bitmap might be slower than a List of Bitmap.

Maybe adding data to the Dictionnary will be faster, but removing for a List will be faster.

Each type of variable and each type of operation might go its own way as far as performance in concerned.

Note also that each has a different use. So the way you use them has an impact on your decision.

A List is limited to an access through a numeric key: x(1)

A Dictionary lets you specify the type of the key, so yo migth endup with: x("City") or x(Date.Today), wich might make more sense to you than x(1), depending on how the collection is used.

Now, if you key is an Integer, I bet that a List would be faster, because it was built from the ground around an Integer key, while the Dictionary was built with any type of value as the key. But who knows until it has been tested for your conditions.

Since both have basically the same properties and methods, you can easily test them both with the same code. So making comparisons is just a matter of a few minutes of testing, in your environment, with your type of data, with the kind operations you are most likely to do with them.

0
 
LVL 12

Expert Comment

by:jmcmunn
ID: 36907598

If you are doing lots of lookups, use a dictionary instead of a list:
http://www.dotnetperls.com/dictionary-time

Good discussion of lots of data collection types here:
http://stackoverflow.com/questions/128636/net-data-structures-arraylist-list-hashtable-dictionary-sortedlist-sortedd
0
 

Author Closing Comment

by:sachin233
ID: 36934735
Accepted
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question