यह जांचने के लिए कि क्या सॉर्टेडसेट और निर्दिष्ट संग्रह में समान तत्व हैं, कोड इस प्रकार है -
उदाहरण
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet<int> set1 = new SortedSet<int>();
set1.Add(100);
set1.Add(200);
set1.Add(300);
SortedSet<int> set2 = new SortedSet<int>();
set2.Add(450);
set2.Add(550);
set2.Add(650);
set2.Add(750);
set2.Add(800);
Console.WriteLine("Does it contain the same elements? = "+set1.SetEquals(set2));
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Does it contain the same elements? = False
उदाहरण
आइए एक और उदाहरण देखें -
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet<int> set1 = new SortedSet<int>();
set1.Add(100);
set1.Add(200);
set1.Add(300);
SortedSet<int> set2 = new SortedSet<int>();
set2.Add(100);
set2.Add(200);
set2.Add(300);
Console.WriteLine("Does it contain the same elements? = "+set1.SetEquals(set2));
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Does it contain the same elements? = True