The source code to get the index of the specified key in a SortedList is given below. The given program is compiled and executed successfully.
using System;
using System.Collections;
class SortedListEx
{
//Entry point of Program
static public void Main()
{
//Creation of SortedList object
SortedList list = new SortedList();
int index = 0;
//Add elements to SortedList
list.Add(101, "India");
list.Add(105, "America");
list.Add(102, "Austrelia");
list.Add(103, "Africa");
list.Add(104, "Canada");
Console.WriteLine("Index of keys:");
foreach (int key in list.GetKeyList())
{
index = list.IndexOfKey(key);
Console.WriteLine("Key "+key+" at index: "+index);
}
}
}
Output:
Index of keys:
Key 101 at index: 0
Key 102 at index: 1
Key 103 at index: 2
Key 104 at index: 3
Key 105 at index: 4
Press any key to continue . . .
Program:
The source code to get the index of the specified key in a SortedList is given below. The given program is compiled and executed successfully.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer