Get the key at the specified index of a SortedList in CSharp

Description

The following code shows how to get the key at the specified index of a SortedList.

Example


using System;/*  w  ww  .  j  a v a2 s.co m*/
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.





















Home »
  C# Tutorial »
    Collections »




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