VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-check-if-the-sortedset-contains-a-specific-element/

⇱ C# | Check if the SortedSet contains a specific element - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Check if the SortedSet contains a specific element

Last Updated : 11 Jul, 2025
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:
Output:
True
Example 2:
Comment

Explore