उदाहरण
SortedSet<T> की IsSubsetOf() मेथड जांचती है कि क्या वर्तमान सेट निर्दिष्ट कलेक्शन का सबसेट है (यानी इसके सभी तत्व निर्दिष्ट कलेक्शन में मौजूद हैं)।
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("SortedSet1, SortedSet2 का सबसेट है? = " + set1.IsSubsetOf(set2));
}
}
आउटपुट
SortedSet1 में तत्व... AB BC CD EF SortedSet2 में तत्व... AB BC CD DE EF HI JK SortedSet1, SortedSet2 का सबसेट है? = True
एक और उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet<string> set1 = new SortedSet<string>();
set1.Add("CD");
set1.Add("CD");
set1.Add("CD");
set1.Add("CD");
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("SortedSet1, SortedSet2 का सबसेट है? = " + set1.IsSubsetOf(set2));
}
}
आउटपुट
SortedSet1 में तत्व... CD SortedSet2 में तत्व... AB BC CD DE EF HI JK SortedSet1, SortedSet2 का सबसेट है? = True