C# | Check if SortedSet and the specified collection contain the same elements Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet.SetEquals(IEnumerable) Method is used to check whether the SortedSet and the specified collection contain the same elements. Properties: In C#, SortedSet class can be used to store, remove or view elements. It maintains ascending order and does not store duplicate elements. It is suggested to use SortedSet class if you have to store unique elements and maintain ascending order. Syntax: mySortedSet1.SetEquals(mySortedSet2); Here, mySortedSet1 and mySortedSet2 are two SortedSet. Return Value: The function returns True if mySortedSet1 and mySortedSet2 are equal, else returns False. Exception: This method will give ArgumentNullException if the SortedSet is null. Example 1: CSHARP // C# code to Check if SortedSet // and the specified collection // contain the same elements using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of integers SortedSet<int> mySortedSet1 = new SortedSet<int>(); // adding elements in mySortedSet1 mySortedSet1.Add(1); mySortedSet1.Add(2); mySortedSet1.Add(3); mySortedSet1.Add(4); mySortedSet1.Add(5); // Creating a SortedSet of integers SortedSet<int> mySortedSet2 = new SortedSet<int>(); // adding elements in mySortedSet2 mySortedSet2.Add(1); mySortedSet2.Add(2); mySortedSet2.Add(3); mySortedSet2.Add(4); mySortedSet2.Add(5); // Check if SortedSet and the specified // collection contain the same elements Console.WriteLine(mySortedSet1.SetEquals(mySortedSet2)); } } Output: True Example 2: CSHARP // C# code to Check if SortedSet and // the specified collection // contain the same elements using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of strings SortedSet<string> mySortedSet1 = new SortedSet<string>(); // adding elements in mySortedSet1 mySortedSet1.Add("A"); mySortedSet1.Add("B"); mySortedSet1.Add("C"); mySortedSet1.Add("D"); mySortedSet1.Add("E"); // Creating a SortedSet of strings SortedSet<string> mySortedSet2 = new SortedSet<string>(); // adding elements in mySortedSet2 mySortedSet2.Add("F"); mySortedSet2.Add("G"); mySortedSet2.Add("H"); mySortedSet2.Add("I"); mySortedSet2.Add("J"); // Check if SortedSet and the specified // collection contain the same elements Console.WriteLine(mySortedSet1.SetEquals(mySortedSet2)); } } Output: False Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.sortedset-1.setequals?view=netframework-4.7.2#System_Collections_Generic_SortedSet_1_SetEquals_System_Collections_Generic_IEnumerable__0__ Comment More infoAdvertise with us Next Article C# | Check if SortedSet and the specified collection contain the same elements S Sahil_Bansall Follow Improve Article Tags : Misc C# CSharp-method CSharp-Generic-SortedSet CSharp-Generic-Namespace +1 More Practice Tags : Misc Similar Reads C# | Check if HashSet and the specified collection contain the same elements Here's an example code that demonstrates how to use the Overlaps method to check if a HashSet and a specified collection share common elements in C#: C# using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // Create a HashSet and a List HashSet<int> 3 min read C# | Check if SortedSet and a specified collection share common elements SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet.Overlaps(IEnumerable) Method is used to check whether a SortedSet and a specified collection share common elements or not. Properties: In C#, SortedSet cla 2 min read C# | Check if the SortedSet contains a specific element SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Contains(T) Method is used to check if a SortedSet contains a specific element or not. Properties: In C#, SortedSet class can be used to store, remov 2 min read C# | Check if a SortedSet is a subset of the specified collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.IsSubsetOf(IEnumerable<T>) Method is used to check whether a SortedSet<T> object is a subset of the specified collection or not. Properties: In 2 min read C# | Check if a SortedSet is a superset of the specified collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.IsSupersetOf(IEnumerable<T>) method is used to check whether a SortedSet<T> object is a superset of the specified collection. Properties: In C# 2 min read Like