Mega Code Archive

 
Categories / C# / Collections Data Structure
 

SortedList SetByIndex replaces the value at a specific index in a SortedList object

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" );       PrintIndexAndKeysAndValues( mySL );       mySL.SetByIndex( 3, "III" );       mySL.SetByIndex( 4, "IV" );       PrintIndexAndKeysAndValues( mySL );    }    public static void PrintIndexAndKeysAndValues( SortedList myList )  {       for ( int i = 0; i < myList.Count; i++ )  {          Console.WriteLine( "\t[{0}]:\t{1}\t{2}", i, myList.GetKey(i), myList.GetByIndex(i) );       }    } }