Get the zero-based index of the first occurrence of the specified value in SortedList in CSharp

Description

The following code shows how to get the zero-based index of the first occurrence of the specified value in SortedList.

Example


using System;//from  ww  w. j a  v  a2 s.  c o  m
using System.Collections;

class MainClass
{

  public static void Main()
  {
    SortedList mySortedList = new SortedList();

    mySortedList.Add("NY", "New York");
    mySortedList.Add("FL", "Florida");
    mySortedList.Add("AL", "Alabama");
    mySortedList.Add("WY", "Wyoming");
    mySortedList.Add("CA", "California");

    int myIndex = mySortedList.IndexOfValue("New York");
    Console.WriteLine("The index of New York is " + myIndex);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary