You should never use
Hashtable
or any other non-generic collections in new development. They are superseded by a set of generic types as early as of .NET Framework v.2.0, when generics were introduced. Non-generic non-specialized collections are bad due to a need for type casts.
Choose from
System.Collection.Generic.Dictionary
,
System.Collection.Generic.SortedDictionary
or
System.Collection.Generic.SortedList
; they differ mostly in different trade-off between redundancy and performance.
Please see
http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx[
^].
You problem will look like this:
using IntIndexedStringDictionary = Dictionary<int, string>;
using Pair = KeyValuePair<int, string>;
IntIndexedStringDictionary dictionary = new IntIndexedStringDictionary();
dictionary.Add(1, "first");
dictionary.Add(3, "third");
foreach (Pair pair in dictionary) {
int key = pair.Key;
string value = pair.Value;
}
—SA