उदाहरण 1: SortedList को क्लोन करना
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("A", "Jacob");
list.Add("B", "Sam");
list.Add("C", "Tom");
list.Add("D", "John");
list.Add("E", "Tim");
list.Add("F", "Mark");
list.Add("G", "Gary");
list.Add("H", "Nathan");
list.Add("I", "Shaun");
list.Add("J", "David");
Console.WriteLine("SortedList तत्व...");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
ICollection col1 = list.Values;
Console.WriteLine("\nमान...");
foreach(string s in col1)
Console.WriteLine(s);
ICollection col2 = list.Keys;
Console.WriteLine("\nकुंजियाँ...");
foreach(string s in col2)
Console.WriteLine(s);
SortedList list2 = (SortedList)list.Clone();
Console.WriteLine("\nपरिणामी SortedList... उपरोक्त सूची से क्लोन किया गया");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
}
}
आउटपुट
SortedList तत्व...
A Jacob
B Sam
C Tom
D John
E Tim
F Mark
G Gary
H Nathan
I Shaun
J David
मान...
Jacob
Sam
Tom
John
Tim
Mark
Gary
Nathan
Shaun
David
कुंजियाँ...
A
B
C
D
E
F
G
H
I
J
परिणामी SortedList... उपरोक्त सूची से क्लोन किया गया
A Jacob
B Sam
C Tom
D John
E Tim
F Mark
G Gary
H Nathan
I Shaun
J David
उदाहरण 2: GetValueList और Clone का उपयोग
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("One", "IT");
list.Add("Two", "Operations");
list.Add("Three", "Marketing");
list.Add("Four", "Purchase");
list.Add("Five", "Sales");
list.Add("Six", "Finance");
Console.WriteLine("SortedList तत्व...");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nमानों की सूची... SortedList");
IList col = list.GetValueList();
foreach(string res in col) {
Console.WriteLine(res);
}
Console.WriteLine("\nSortedList केवल पढ़ने योग्य? = " + list.IsReadOnly);
SortedList list2 = (SortedList)list.Clone();
Console.WriteLine("\nपरिणामी SortedList... उपरोक्त सूची से क्लोन किया गया");
foreach(DictionaryEntry d in list) {
Console.WriteLine(d.Key + " " + d.Value);
}
}
}
आउटपुट
SortedList तत्व...
Five Sales
Four Purchase
One IT
Six Finance
Three Marketing
Two Operations
मानों की सूची... SortedList
Sales
Purchase
IT
Finance
Marketing
Operations
SortedList केवल पढ़ने योग्य? = False
परिणामी SortedList... उपरोक्त सूची से क्लोन किया गया
Five Sales
Four Purchase
One IT
Six Finance
Three Marketing
Two Operations