Collections in C#.NET (SortedList & Hash Table)
SortedList
static void Main(string[] args)
{
SortedList studentRoll = new SortedList();
studentRoll.Add(4, “Cheng Boon”);
studentRoll.Add(1, “Desmong Tan”);
studentRoll.Add(3, “Poh Kang”);
studentRoll.Add(2, “Wai Yee”);
foreach (int i in studentRoll.Keys)
Console.WriteLine(“Key={0}, Value={1}”, i, studentRoll[i]);
Console.WriteLine();
Console.ReadKey();
}
HashTable
static void Main(string[] args)
{
Hashtable myHash = new Hashtable();
myHash.Add(1, “One”);
myHash.Add(“two”, 2);
myHash.Add(3, 3);
foreach (object i in myHash.Keys)
Console.WriteLine(“Key={0}, Value={1}”, i, myHash[i]);
Console.ReadKey();
}
By
Team CVK (Microsoft Competency)