उदाहरण
SortedSet<T> की Clear() मेथड सेट से सभी तत्वों को हटा देती है। इस उदाहरण में दो SortedSet बनाए गए हैं, दूसरे में तत्व जोड़े गए हैं, फिर Clear() कॉल करके खाली किया गया है।
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet<string> set1 = new SortedSet<string>();
set1.Add("AB");
set1.Add("BC");
set1.Add("CD");
set1.Add("EF");
Console.WriteLine("SortedSet1 में तत्व...");
foreach (string res in set1) {
Console.WriteLine(res);
}
SortedSet<string> set2 = new SortedSet<string>();
set2.Add("BC");
set2.Add("CD");
set2.Add("DE");
set2.Add("EF");
set2.Add("AB");
set2.Add("HI");
set2.Add("JK");
Console.WriteLine("SortedSet2 में तत्व...");
foreach (string res in set2) {
Console.WriteLine(res);
}
Console.WriteLine("SortedSet में तत्वों की संख्या = " + set2.Count);
set2.Clear();
Console.WriteLine("SortedSet में तत्वों की संख्या (अपडेटेड) = " + set2.Count);
}
}
आउटपुट
SortedSet1 में तत्व... AB BC CD EF SortedSet2 में तत्व... AB BC CD DE EF HI JK SortedSet में तत्वों की संख्या = 7 SortedSet में तत्वों की संख्या (अपडेटेड) = 0
एक और उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet<int> set1 = new SortedSet<int>();
set1.Add(100);
set1.Add(200);
set1.Add(300);
set1.Add(400);
Console.WriteLine("SortedSet में तत्व...");
foreach (int res in set1) {
Console.WriteLine(res);
}
Console.WriteLine("SortedSet में तत्वों की संख्या = " + set1.Count);
set1.Clear();
Console.WriteLine("SortedSet में तत्वों की संख्या (अपडेटेड) = " + set1.Count);
}
}
आउटपुट
SortedSet में तत्व... 100 200 300 400 SortedSet में तत्वों की संख्या = 4 SortedSet में तत्वों की संख्या (अपडेटेड) = 0