|
using
System;
using
System.Collections;
class
SortedListDemo
{
public
static void Main()
{
//Create an instance of SortedList
SortedList SL = new
SortedList();
//Add elements(Key-Value pairs) to the SortedList
SL.Add(1,
"Prasad");
SL.Add(2,
"Giri");
SL.Add(3,
"Ravi");
//Loop thru each DictonaryEntry and print key and value of each element
foreach (DictionaryEntry DE
in SL)
{
Console.WriteLine("Key =
" + DE.Key.ToString() + " Value = "
+ DE.Value.ToString());
}
//determines the number of elements contained in the SortedList
Console.WriteLine("Count = " + SL.Count);
//Determines the capacity of a SortedList
Console.WriteLine("Capcity = " +
SL.Capacity);
//Trims the size of the SortedList to the actual number of elements present
SL.TrimToSize();
Console.WriteLine("After trimming, Capcity = "
+ SL.Capacity);
}
}
|