How Remove the element with the specified key from a SortedList In C#?

How Remove the element with the specified key from a SortedList In C#?

 

using System;
using System.Collections;
  
class USINGCSHARP {  
    
    public static void Main()
    {
          
        SortedList ucSortedList = new SortedList();
          
        ucSortedList.Add("1", "INDIA");
        ucSortedList.Add("2", "NEW-YORK");
        ucSortedList.Add("3", "UNITED KINGDOM");
        ucSortedList.Add("4", "GERMANY");
        ucSortedList.Add("5", "CHINA");  
        
        foreach (string mykey in ucSortedList.Keys)
            Console.WriteLine("Key = " + mykey);
  
        foreach (string myvalue in ucSortedList.Values)
            Console.WriteLine("Key = " + myvalue);
  
        // Removing element key as "4"
        Console.WriteLine("Removing element have key is 4");
  
        mySortedList.Remove("4");  
        
        foreach (string mykey in ucSortedList.Keys)
            Console.WriteLine("Key = " + mykey);
  
        foreach (string myvalue in ucSortedList.Values)
            Console.WriteLine("Key = " + myvalue);
    }
}

2021-10-03