C# SortedList GetKey
Description
SortedList GetKey
gets the key at the specified index
of a SortedList object.
Syntax
SortedList.GetKey
has the following syntax.
public virtual Object GetKey(
int index
)
Parameters
SortedList.GetKey
has the following parameters.
index
- The zero-based index of the key to get.
Returns
SortedList.GetKey
method returns The key at the specified index of the SortedList object.
Example
using System;/*w ww. j ava 2s .c om*/
using System.Collections;
public class SamplesSortedList {
public static void Main() {
SortedList mySL = new SortedList();
mySL.Add( 1.3, "fox" );
mySL.Add( 1.4, "jumped" );
mySL.Add( 1.5, "over" );
mySL.Add( 1.2, "brown" );
int myIndex=3;
Console.WriteLine( "The key at index {0} is {1}.", myIndex, mySL.GetKey( myIndex ) );
Console.WriteLine( "The value at index {0} is {1}.", myIndex, mySL.GetByIndex( myIndex ) );
IList myKeyList = mySL.GetKeyList();
IList myValueList = mySL.GetValueList();
for ( int i = 0; i < mySL.Count; i++ )
Console.WriteLine( "\t{0}\t{1}", myKeyList[i], myValueList[i] );
}
}
The code above generates the following result.