C# में एक SortedSet ऑब्जेक्ट निर्दिष्ट संग्रह का उचित सुपरसेट है या नहीं, यह जांचने के लिए IsProperSupersetOf() मेथड का उपयोग किया जाता है। यह मेथड true लौटाता है यदि सेट निर्दिष्ट संग्रह के सभी तत्वों को रखता है और कम से कम एक अतिरिक्त तत्व भी रखता है।
उदाहरण 1
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet set1 = new SortedSet();
set1.Add(10);
set1.Add(20);
set1.Add(30);
set1.Add(40);
set1.Add(50);
set1.Add(60);
Console.WriteLine("SortedSet1 में तत्व...");
foreach (int res in set1) {
Console.WriteLine(res);
}
SortedSet set2 = new SortedSet();
set2.Add(10);
set2.Add(20);
set2.Add(30);
set2.Add(40);
set2.Add(50);
set2.Add(60);
set2.Add(70);
set2.Add(80);
set2.Add(90);
set2.Add(100);
Console.WriteLine("SortedSet2 में तत्व...");
foreach (int res in set2) {
Console.WriteLine(res);
}
Console.WriteLine("क्या SortedSet2, SortedSet1 का उचित सुपरसेट है? = " + set2.IsProperSupersetOf(set1));
}
}
आउटपुट
SortedSet1 में तत्व... 10 20 30 40 50 60 SortedSet2 में तत्व... 10 20 30 40 50 60 70 80 90 100 क्या SortedSet2, SortedSet1 का उचित सुपरसेट है? = True
उदाहरण 2
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet set1 = new SortedSet();
set1.Add(10);
set1.Add(10);
set1.Add(10);
set1.Add(10);
Console.WriteLine("SortedSet1 में तत्व...");
foreach (int res in set1) {
Console.WriteLine(res);
}
SortedSet set2 = new SortedSet();
set2.Add(10);
set2.Add(20);
set2.Add(30);
set2.Add(40);
set2.Add(50);
set2.Add(60);
set2.Add(70);
set2.Add(80);
set2.Add(90);
set2.Add(100);
Console.WriteLine("SortedSet2 में तत्व...");
foreach (int res in set2) {
Console.WriteLine(res);
}
Console.WriteLine("क्या SortedSet2, SortedSet1 का उचित सुपरसेट है? = " + set2.IsProperSupersetOf(set1));
}
}
आउटपुट
SortedSet1 में तत्व... 10 SortedSet2 में तत्व... 10 20 30 40 50 60 70 80 90 100 क्या SortedSet2, SortedSet1 का उचित सुपरसेट है? = True