If you are using .NET 2.0 or later consider using Dictionary<> generic instead of Hashtable as it will be strongly typed. That elliminates the need to cast values as Hashtable works with object.
Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("key1", "value1"); string value = dict["key1"];
foreach (string key in dict.Keys) { value = dict[key]; }
How to retrieve value from key
Eric66
To get the value, use:
ht["key1"]
IvanBi
The next step is to grab all of the values in a hashtable. This should help.
foreach(DictionaryEntry _d in ht)
{
MessageBox.Show(_d.Key + "-" + _d.Value);
}
tanzirmusabbir
If you are using .NET 2.0 or later consider using Dictionary<> generic instead of Hashtable as it will be strongly typed. That elliminates the need to cast values as Hashtable works with object.
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("key1", "value1");
string value = dict["key1"];
foreach (string key in dict.Keys)
{
value = dict[key];
}