Remove the element at the specified index of a SortedList in CSharp

Description

The following code shows how to remove the element at the specified index of a SortedList.

Example


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

   public static void Main()  {
      SortedList mySL = new SortedList();
      mySL.Add( "3c", "dog" );
      mySL.Add( "2c", "over" );
      mySL.Add( "1c", "brown" );
      mySL.Add( "1a", "The" );
      mySL.Add( "1b", "quick" );
      mySL.Add( "3a", "the" );
      mySL.Add( "3b", "lazy" );
      mySL.Add( "2a", "fox" );
      mySL.Add( "2b", "jumped" );

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


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

   }

}

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