Hashtable retrieve value by position?

c#

Solution

The `Hashtable` (and `Dictionary`) class is not ordered, meaning, it's entries don't have any order or position, and even if you get a list of keys, the order is random. If you want to get values by key and position as well, you should use the `OrderedDictionary` collection.

Problem

``` public static Hashtable Drinks = new Hashtable(); Drinks["Water"] = 3; Drinks["Coffee"] = 2 Drinks["Beer"] = 5; ``` To get the value of item I use: int drink = (int)Drinks["Water"]; which works. I wanted to know how i can make this work. pCardValue1 = (int)card[1]; Like instead of typing the item name i want to get the value by position.

Original source

Related problems