Get zero-based index of the specified key in a SortedList in CSharp
Description
The following code shows how to get zero-based index of the specified key in a SortedList.
Example
using System;//from w ww . jav a 2s . c o m
using System.Collections;
public class SamplesSortedList {
public static void Main() {
SortedList mySL = new SortedList();
mySL.Add( 1, "one" );
mySL.Add( 3, "three" );
mySL.Add( 2, "two" );
mySL.Add( 4, "four" );
mySL.Add( 0, "zero" );
int myKey = 2;
Console.WriteLine(mySL.IndexOfKey( myKey ));
}
}
The code above generates the following result.