SortedList.GetByIndex gets the value at the specified index of a SortedList object. : SortedList « Collections Data Structure « C# / C Sharp






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

   
    
  








Related examples in the same category

1.Create SortedList sorted according to the specified IComparer
2.Create a SortedList using case-insensitive comparer
3.Create a SortedList using CaseInsensitiveComparer based on the Turkish culture (tr-TR)
4.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value.
5.SortedList is a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
6.SortedList.Add Method Adds an element with key and value to a SortedList object.
7.SortedList.Clear removes all elements from a SortedList object.
8.SortedList.Contains Determines whether a SortedList object contains a specific key.
9.SortedList.CopyTo copies SortedList elements to a one-dimensional Array object
10.SortedList.IndexOfKey returns the zero-based index of the specified key in a SortedList object.
11.SortedList.IsSynchronized tells whether access to a SortedList object is synchronized (thread safe).
12.SortedList.Remove removes the element with the specified key from a SortedList object.
13.SortedList.SetByIndex replaces the value at a specific index in a SortedList object.
14.Add element to SortedListAdd element to SortedList
15.Add to SortedList, get by key and index
16.Delete element in a SortedList with RemoveAt
17.illustrates the use of a SortedListillustrates the use of a SortedList
18.illustrates the use of the SortedList methodsillustrates the use of the SortedList methods
19.Demonstrate a SortedListDemonstrate a SortedList
20.Create a SortedList using the default comparer
21.Create a SortedList using the specified case-insensitive comparer
22.Create a SortedList using the specified CaseInsensitiveComparer
23.Parametr Collection