The
SortedList collection stores key-value pairs in the ascending order of key by
default.so The SortedList<> class represents a collection of key/value
pairs that are sorted by key.
Creation
of SortedList
// create a sorted list
SortedList<int, string>
sortedlist11 = new SortedList<int, string>();
//Add items in sorted list
sortedlist11.Add(1,
"Rahul");
sortedlist11.Add(2,
"Nitin");
sortedlist11.Add(3,
"Neelam");
sortedlist11.Add(4,
"Sakshi");
sortedlist11.Add(5,
"Prashant");
//read values from sorted list
foreach
(KeyValuePair<int, string> pair in sortedlist11)
{
Console.WriteLine("{0}
=> {1}", pair.Key, pair.Value);
}
|