Solved

When and why to use IDictionary

Posted on 2006-06-24
3
407 Views
Last Modified: 2010-05-19
There are many collection classes and generic collection classes.  When do I use IDictionary versus hashtable which also takes a key?

Any "tomes" on this work - when to use what collection?
0
Comment
Question by:vamail2
3 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 200 total points
ID: 16976822
Hi...

Take a look at this link:
http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

Notice the HashTable object signatura:

[SerializableAttribute]
[ComVisibleAttribute(true)]
public class Hashtable : IDictionary, ICollection, IEnumerable,
    ISerializable, IDeserializationCallback, ICloneable

You can see that HashTable actually implements IDictionary!! :)

IDictionary just represents a nongeneric collection of key/value pairs, as you can also read from http://msdn2.microsoft.com/en-us/library/system.collections.idictionary.aspx.
There are more collection objects the implement it... actually all that manage items as a Key/value.

To finish... IDictionary is an interface, you don't actually use it comparativelly to the HashTable class.
You can use IDictionary if you want to create your own custom collection if inheriting from an existing implementation doesn't fit you needs.

Alex :p
0
 
LVL 7

Assisted Solution

by:pradeepsudharsan
pradeepsudharsan earned 50 total points
ID: 16977422
IDictionary is an interface which is used to retrive the key,value pairs from the Hash Table in the order in which you are entered the key,value pairs into the hash table.(First in First Out)

If you use other methods to retrive the key,value pairs from the Hash Table,
they will give you the wrong ordering of results.
0
 

Author Comment

by:vamail2
ID: 16979080
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now