using System;
using System.Collections;
namespace P7_8
{
   
    class Program
    {
        static void Main()
        {
            // һSortedList            
            SortedList mySL = new SortedList();            
            mySL.Add("First", "Hello");            
            mySL.Add("Second", "World");            
            mySL.Add("Third", "!");                     
            Console.WriteLine("mySL");             //оSortedListԡֵ  
            Console.WriteLine("  Count:    {0}", mySL.Count);            
            Console.WriteLine("  Capacity: {0}", mySL.Capacity);            
            Console.WriteLine("  Keys and Values:");            
            PrintIndexAndKeysAndValues(mySL);            
            int myIndex = 2;                     //ָļֵ            
            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));            // SortedListеļбֵб            
            IList myKeyList = mySL.GetKeyList();            
            IList myValueList = mySL.GetValueList();            // Prints the keys in the first column and the values in the second column.            
            Console.WriteLine("\t-KEY-\t-VALUE-");            
            for (int i = 0; i < mySL.Count; i++)                
                Console.WriteLine("\t{0}\t{1}", myKeyList[i], myValueList[i]);            
            // ָ            
            string myKey = "Second";            
             // ֵָ            
      	    Console.WriteLine("The key \"{0}\" is at index {1}.", myKey, mySL.IndexOfKey(myKey));  
            String myValue = "World";            
             // ֵָ            
Console.WriteLine("The value \"{0}\" is at index {1}.", myValue, mySL.IndexOfValue(myValue)); 
            mySL.SetByIndex(1, "I");            
            mySL.SetByIndex(2, "II");            //ӡʾбļֵ            
            Console.WriteLine("After replacing the value at index1 and index 1,");            
            PrintIndexAndKeysAndValues(mySL);            
            Console.ReadKey();        
        }        
        //ӡSortedListеļֵ        
        public static void PrintIndexAndKeysAndValues(SortedList myList)        
        {            
            Console.WriteLine("\t-INDEX-\t-KEY-\t-VALUE-");            
            for (int i = 0; i < myList.Count; i++)            
            {                
                Console.WriteLine("\t[{0}]:\t{1}\t{2}", i, myList.GetKey(i), myList.GetByIndex(i));            
            }            
            Console.WriteLine();        
        }
    }
}
