C# | Check if the SortedSet contains a specific element 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<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, 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: public virtual bool Contains (T item); Here, T is Type Parameter, i.e, the type of elements in the set. Return Value: The method returns True if the set contains the specified item, otherwise, returns False. Example 1: CSHARP // C# code to check if the SortedSet // contains a specific element using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of integers SortedSet<int> mySortedSet = new SortedSet<int>(); // adding elements in mySortedSet mySortedSet.Add(2); mySortedSet.Add(4); mySortedSet.Add(6); mySortedSet.Add(8); mySortedSet.Add(10); // Checking if the SortedSet contains // a specific element Console.WriteLine(mySortedSet.Contains(6)); } } Output: True Example 2: CSHARP // C# code to check if the SortedSet // contains a specific element using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of strings SortedSet<string> mySortedSet = new SortedSet<string>(); // adding elements in mySortedSet mySortedSet.Add("Mumbai"); mySortedSet.Add("Bangalore"); mySortedSet.Add("Chandigarh"); mySortedSet.Add("Noida"); mySortedSet.Add("Jaipur"); mySortedSet.Add("Kolkata"); // Checking if the SortedSet contains // a specific element Console.WriteLine(mySortedSet.Contains("Delhi")); } } Output: False Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.sortedset-1.contains?view=netcore-2.1 Comment More infoAdvertise with us Next Article C# | Check if the SortedSet contains a specific element 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 a HashSet contains the specified element A HashSet is an unordered collection of the unique elements. It is found in System.Collections.Generic namespace. It is used in a situation where we want to prevent duplicates from being inserted in the collection. As far as performance is concerned, it is better in comparison to the list. HashSet.C 2 min read C# | Check if SortedSet and the specified collection contain the same elements 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 c 2 min read C# | Check whether a SortedList object contains a specific key SortedList.Contains(Object) Method is used to check whether a SortedList object contains a specific key. Syntax: public virtual bool Contains (object key); Here, key is the Key which is to be located in the SortedList object. Return Value: This method returns the true if the SortedList object contai 2 min read C# | Check if a SortedList object contains a specific value SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.ContainsValue(Object) method is used to check whether a SortedList o 2 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 Like