The source code to create a shallow copy of a SortedList object is given below. The given program is compiled and executed successfully.
using System;
using System.Collections;
class SortedListEx
{
//Entry point of Program
static public void Main()
{
//Creation of SortedList object
SortedList list1 = new SortedList();
SortedList list2;
//Add elements to SortedList
list1.Add(101, "India ");
list1.Add(105, "America ");
list1.Add(102, "Austrelia");
list1.Add(103, "Africa ");
list1.Add(104, "Canada ");
Console.WriteLine("List1 Values:");
foreach (string value in list1.Values)
{
Console.WriteLine("\t" + value);
}
list2 = (SortedList)list1.Clone();
Console.WriteLine("List2 Values(Shallow copy of list1):");
foreach (string value in list2.Values)
{
Console.WriteLine("\t" + value);
}
}
}
Output:
List1 Values:
India
Austrelia
Africa
Canada
America
List2 Values(Shallow copy of list1):
India
Austrelia
Africa
Canada
America
Press any key to continue . . .
Program:
The source code to create a shallow copy of a SortedList object is given below. The given program is compiled and executed successfully.
Output: