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: