Mega Code Archive

 
Categories / C# / Collections Data Structure
 

SortedList GetByIndex gets the value at the specified index of a SortedList object

using System; 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] );    } }