Dictionary implementation of ListDictionary, HybridDictionary, and OrderedDictionary
ListDictionary myEmailLookup = new ListDictionary ();
myEmailLookup["sbishop@contoso.com"] = "Bishop, Scott";
myEmailLookup["chess@contoso.com"] = "Hess, Christian";
myEmailLookup["djump@contoso.com"] = "Jump, Dan";
foreach (DictionaryEntry entry in myEmailLookup)
{
Console.WriteLine(entry.Value);
}
This is very similar to has in a way its being implemented as we can see.
ListDictionary is good if you know that you are dealing with small list. What if size is unknown then you will use HybridDictionary which starts as ListDictionary and then list grows in size converts itself into Hashtable
HybridDictionary myEmail = new HybridDictionary ();
myEmail["sbishop@contoso.com"] = "Jame, Gath";
myEmail["chess@contoso.com"] = "Todd, Sims";
myEmail["djump@contoso.com"] = "Garry, Trap";
foreach (DictionaryEntry entry in myEmail)
{
Console.WriteLine(entry.Value);
}
If you really need an ordered Hashtable then you should switch to OrderedDictionary which possesses following Properties and Methods.
Properties
Name | Description |
---|---|
Item | Overloaded to support access by index |
Methods
Name | Description |
---|---|
Insert | Inserts a key/value pair at a specific index in the collection |
RemoveAt | Removes a key/value pair at a specific index in the collection |