SortedSet<T>.SetEquals(IEnumerable<T>) मेथड जांचता है कि क्या वर्तमान SortedSet और निर्दिष्ट संग्रह में ठीक वही तत्व हैं (क्रम की परवाह किए बिना, क्योंकि दोनों क्रमबद्ध हैं)। यह बूलियन लौटाता है।
उदाहरण 1: अलग-अलग तत्व
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
उदाहरण 2: समान तत्व
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
SetEquals O(n) समय में काम करता है। यह सेट समानता की जांच करता है (समान तत्व, समान क्रम आवश्यक नहीं क्योंकि SortedSet क्रमबद्ध है)। Overlaps कम से कम एक सामान्य तत्व की जांच करता है। IsSubsetOf/IsSupersetOf आंशिक समावेश की जांच करते हैं।