Print out the keys and Data of a Hashtable in C# .NET 1.1
问题 I need debug some old code that uses a Hashtable to store response from various threads. I need a way to go through the entire Hashtable and print out both keys and the data in the Hastable. How can this be done? 回答1: foreach(string key in hashTable.Keys) { Console.WriteLine(String.Format("{0}: {1}", key, hashTable[key])); } 回答2: I like: foreach(DictionaryEntry entry in hashtable) { Console.WriteLine(entry.Key + ":" + entry.Value); } 回答3: public static void PrintKeysAndValues( Hashtable