उदाहरण
HashSet<T> की IsProperSupersetOf() मेथड जांचती है कि क्या वर्तमान सेट निर्दिष्ट कलेक्शन का उचित सुपरसेट है (यानी इसमें निर्दिष्ट कलेक्शन के सभी तत्व हैं और कम से कम एक अतिरिक्त तत्व भी है)।
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
HashSet<int> set1 = new HashSet<int>();
set1.Add(30);
set1.Add(60);
set1.Add(70);
set1.Add(80);
set1.Add(100);
set1.Add(125);
set1.Add(150);
set1.Add(200);
Console.WriteLine("HashSet1 में तत्व");
foreach(int val in set1) {
Console.WriteLine(val);
}
HashSet<int> set2 = new HashSet<int>();
set2.Add(30);
set2.Add(60);
set2.Add(70);
Console.WriteLine("HashSet2 में तत्व");
foreach(int val in set2) {
Console.WriteLine(val);
}
Console.WriteLine("क्या set1, set2 का उचित सुपरसेट है? " + set1.IsProperSupersetOf(set2));
}
}
आउटपुट
HashSet1 में तत्व 30 60 70 80 100 125 150 200 HashSet2 में तत्व 30 60 70 क्या set1, set2 का उचित सुपरसेट है? True
एक और उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
HashSet<string> set1 = new HashSet<string>();
set1.Add("AB");
set1.Add("CD");
set1.Add("EF");
set1.Add("GH");
set1.Add("IJ");
set1.Add("KL");
set1.Add("MN");
set1.Add("OP");
Console.WriteLine("HashSet1 में तत्व");
foreach(string val in set1) {
Console.WriteLine(val);
}
HashSet<string> set2 = new HashSet<string>();
set2.Add("EF");
set2.Add("KL");
Console.WriteLine("HashSet2 में तत्व");
foreach(string val in set2) {
Console.WriteLine(val);
}
Console.WriteLine("क्या set1, set2 का उचित सुपरसेट है? " + set1.IsProperSupersetOf(set2));
}
}
आउटपुट
HashSet1 में तत्व AB CD EF GH IJ KL MN OP HashSet2 में तत्व EF KL क्या set1, set2 का उचित सुपरसेट है? True