The source code to get the index of the first occurrence of the specified value 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 Values:");
foreach (string value in list.GetValueList())
{
index = list.IndexOfValue(value);
Console.WriteLine("Value ""+value+"" at index: "+index);
}
}
}
Output:
Index of Values:
Value "India " at index: 0
Value "Austrelia" at index: 1
Value "Africa " at index: 2
Value "Canada " at index: 3
Value "America " at index: 4
Press any key to continue . . .
Program:
The source code to get the index of the first occurrence of the specified value in a SortedList is given below. The given program is compiled and executed successfully.
Output: