Sorting a hashtable in C#

Hashtable myHashTable = new Hashtable();
myHashTable.Add("1", "dotnet");
myHashTable.Add("2", "tutorials");
myHashTable.Add("3", "w3mentor");
 
List<int> myList = new List<int>();
foreach (var key in hash.Keys)
{
   myList.Add(int.Parse(key.ToString())); 
}
//sort the hashtable
myList.Sort();
 
foreach (var item in myList)
{
     Console.WriteLine(string.Format("{0},{1}", item, hash[item.ToString()]));
}
 
Console.Read();

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.