उदाहरण
HashSet<T> की IsSupersetOf() मेथड जांचती है कि क्या वर्तमान सेट निर्दिष्ट कलेक्शन का सुपरसेट है।
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("AB"); // डुप्लीकेट
set1.Add("IJ");
set1.Add("KL");
set1.Add("EF"); // डुप्लीकेट
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.IsSupersetOf(set2));
}
}
आउटपुट
HashSet1 में तत्व AB CD EF IJ KL OP HashSet2 में तत्व EF KL क्या set1, set2 का सुपरसेट है? True
एक और उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
HashSet<string> set1 = new HashSet<string>();
set1.Add("IJ");
set1.Add("KL");
set1.Add("EF");
set1.Add("OP");
Console.WriteLine("HashSet1 में तत्व");
foreach(string val in set1) {
Console.WriteLine(val);
}
HashSet<string> set2 = new HashSet<string>();
set2.Add("KL");
set2.Add("MN");
set2.Add("OP");
set2.Add("QR");
Console.WriteLine("HashSet2 में तत्व");
foreach(string val in set2) {
Console.WriteLine(val);
}
Console.WriteLine("क्या set1, set2 का सुपरसेट है? " + set1.IsSupersetOf(set2));
}
}
आउटपुट
HashSet1 में तत्व IJ KL EF OP HashSet2 में तत्व KL MN OP QR क्या set1, set2 का सुपरसेट है? False