C# में SortedSet किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है।
उदाहरण 1
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet set1 = new SortedSet();
set1.Add("CD");
set1.Add("CD");
set1.Add("CD");
set1.Add("CD");
Console.WriteLine("SortedSet1 में तत्व...");
foreach (string res in set1) {
Console.WriteLine(res);
}
Console.WriteLine("क्या SortedSet1 में तत्व DE है? = " + set1.Contains("DE"));
SortedSet set2 = new SortedSet();
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("क्या SortedSet2, SortedSet1 का सुपरसेट है? = " + set2.IsSupersetOf(set1));
}
}
आउटपुट
SortedSet1 में तत्व... CD क्या SortedSet1 में तत्व DE है? = False SortedSet2 में तत्व... AB BC CD DE EF HI JK क्या SortedSet2, SortedSet1 का सुपरसेट है? = True
उदाहरण 2
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet mySet = new SortedSet();
mySet.Add(100);
mySet.Add(200);
mySet.Add(300);
mySet.Add(400);
Console.WriteLine("SortedSet में तत्व...");
foreach (int res in mySet) {
Console.WriteLine(res);
}
Console.WriteLine("क्या SortedSet में तत्व 400 है? = " + mySet.Contains(400));
}
}
आउटपुट
SortedSet में तत्व... 100 200 300 400 क्या SortedSet में तत्व 400 है? = True