VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-get-the-number-of-elements-in-the-sortedset/

⇱ C# | Get the number of elements in the SortedSet - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Get the number of elements in the SortedSet

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>.Count Property is used to get the number of elements in the SortedSet. 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:
mySortedSet.Count
Here, mySortedSet is a SortedSet. Below given are some examples to understand the implementation in a better way: Example 1:
Output:
The number of elements in mySortedSet are: 5
Example 2:
Comment

Explore