Replace the value at a specific index in a SortedList in CSharp

Description

The following code shows how to replace the value at a specific index in a SortedList.

Example


//from w ww . ja  va 2s  .  co  m
using System;
using System.Collections;
public class SamplesSortedList  {

   public static void Main()  {
      SortedList mySL = new SortedList();
      mySL.Add( 2, "two" );
      mySL.Add( 3, "three" );
      mySL.Add( 1, "one" );
      mySL.Add( 0, "zero" );
      mySL.Add( 4, "four" );


      foreach (string myKey in mySL.Keys)
      {
          Console.WriteLine("myKey = " + myKey);
      }
    
      foreach(string myValue in mySL.Values)
      {
          Console.WriteLine("myValue = " + myValue);
      } 
      mySL.SetByIndex( 3, "III" );


      foreach (string myKey in mySL.Keys)
      {
          Console.WriteLine("myKey = " + myKey);
      }
    
      foreach(string myValue in mySL.Values)
      {
          Console.WriteLine("myValue = " + myValue);
      } 
   }
}




















Home »
  C# Tutorial »
    Collections »




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