Skip to content

Instantly share code, notes, and snippets.

@tnngo2
Created April 24, 2012 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnngo2/2477903 to your computer and use it in GitHub Desktop.
Save tnngo2/2477903 to your computer and use it in GitHub Desktop.
class SortedCollection
{
static void Main(string[] args)
{
SortedList objSortList = new SortedList();
objSortList.Add("John", "Administration");
objSortList.Add("Jack", "Human Resource");
objSortList.Add("Peter", "Finance");
objSortList.Add("Joel", "Marketing");
Console.WriteLine("Original values stored in the sorted list");
Console.WriteLine("Key \t\t Values");
for (int i = 0; i < objSortList.Count; i++)
{
Console.WriteLine(objSortList.GetKey(i) + "\t\t" + objSortList.GetByIndex(i));
}
if (!objSortList.ContainsKey("Jerry"))
{
objSortList.Add("Jerry","Construction");
}
objSortList["Peter"] = "Engineering";
objSortList["Jerry"] = "Information Technology";
Console.WriteLine();
Console.WriteLine("Update values stored in hash table");
Console.WriteLine("Key \t\t Values");
for (int i = 0; i < objSortList.Count; i++)
{
Console.WriteLine(objSortList.GetKey(i) + " \t\t" + objSortList.GetByIndex(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment