What is a SortedSet<T> in C#?
SortedSet<T> is a collection that stores unique elements in sorted order.
- Implements a self-balancing binary search tree (usually a Red-Black Tree).
- Automatically maintains elements in ascending sorted order.
- Provides set operations like union, intersection, and difference.
Example:
SortedSet<int> sortedSet = new SortedSet<int> { 5, 1, 3 };
sortedSet.Add(2); // Sorted order maintained: {1, 2, 3, 5}
Follow: