Hi all,
I'm new to C# (better at asp.net) and am having trouble with looping thru a hashtable. I can loop thru the keys but can't get the value if using a foreach loop. If I use a while loop with an enumerator I can get the keys and values. I want to do this in a foreach loop but can't. Here is some of what I've tried. Any help would be appreciated.
Thanks for your time, Mike
I'm new to C# (better at asp.net) and am having trouble with looping thru a hashtable. I can loop thru the keys but can't get the value if using a foreach loop. If I use a while loop with an enumerator I can get the keys and values. I want to do this in a foreach loop but can't. Here is some of what I've tried. Any help would be appreciated.
Code:
h.Add("aa", "apple");
h.Add("bb", "balloon");
//can get the keys but not the value at each key
foreach (string s in h.keys)
{
//Console.WriteLine(s + ": " + h(s) + "\n");
Console.WriteLine(s + ":" );
}
//works but want to do it in a foreach...
IDictionaryEnumerator myEnum = h.GetEnumerator();
while ( myEnum.MoveNext() ){
Console.WriteLine("\t{0}:\t{1}", myEnum.Key, myEnum.Value);
Console.WriteLine();
}
//not sure what to do here
foreach (myEnum.key in myEnum){
Console.WriteLine("\t{0}:\t{1}", myEnum.Key, myEnum.Key);
}
Thanks for your time, Mike