<p>I need debug some old code that uses a Hashtable to store response from various threads.</p>

<p>I need a way to go through the entire Hashtable and print out both keys and the data in the Hastable.</p>

<p>How can this be done?</p>

[{'answer_id': 34884, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 6, 'selected': True, 'text': '<pre><code>foreach(string key in hashTable.Keys)\n{\n   Console.WriteLine(String.Format("{0}: {1}", key, hashTable[key]));\n}\n</code></pre>\n'}, {'answer_id': 34887, 'author': 'Dinah', 'author_id': 356, 'author_profile': 'https://Stackoverflow.com/users/356', 'pm_score': 2, 'selected': False, 'text': '<pre><code>\n   public static void PrintKeysAndValues( Hashtable myList )  {\n      IDictionaryEnumerator myEnumerator = myList.GetEnumerator();\n      Console.WriteLine( "\\t-KEY-\\t-VALUE-" );\n      while ( myEnumerator.MoveNext() )\n         Console.WriteLine("\\t{0}:\\t{1}", myEnumerator.Key, myEnumerator.Value);\n      Console.WriteLine();\n   }\n</code></pre>\n\n<p>from: <a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.collections.hashtable(VS.71).aspx</a></p>\n'}, {'answer_id': 34894, 'author': 'Dillie-O', 'author_id': 71, 'author_profile': 'https://Stackoverflow.com/users/71', 'pm_score': 1, 'selected': False, 'text': '<p>This should work for pretty much every version of the framework...</p>\n\n<pre><code>foreach (string HashKey in TargetHash.Keys)\n{\n   Console.WriteLine("Key: " + HashKey + " Value: " + TargetHash[HashKey]);\n}\n</code></pre>\n\n<p>The trick is that you can get a list/collection of the keys (or the values) of a given hash to iterate through.</p>\n\n<p>EDIT: Wow, you try to pretty your code a little and next thing ya know there 5 answers... 8^D</p>\n'}, {'answer_id': 34909, 'author': 'David Basarab', 'author_id': 2469, 'author_profile': 'https://Stackoverflow.com/users/2469', 'pm_score': 1, 'selected': False, 'text': '<p>I also found that this will work too.</p>\n\n<pre><code>System.Collections.IDictionaryEnumerator enumerator = hashTable.GetEnumerator();\n\nwhile (enumerator.MoveNext())\n{\n    string key = enumerator.Key.ToString();\n    string value = enumerator.Value.ToString();\n\n    Console.WriteLine(("Key = \'{0}\'; Value = \'{0}\'", key, value);\n}\n</code></pre>\n\n<p>Thanks for the help.</p>\n'}, {'answer_id': 35024, 'author': 'Jake Pearson', 'author_id': 632, 'author_profile': 'https://Stackoverflow.com/users/632', 'pm_score': 3, 'selected': False, 'text': '<p>I like:</p>\n\n<pre><code>foreach(DictionaryEntry entry in hashtable)\n{\n    Console.WriteLine(entry.Key + ":" + entry.Value);\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/34879', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2469/']