Home » C# SortedSet

C# SortedSet<T>

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. It is found in System.Collections.Generic namespace.

C# SortedSet<T> example

Let’s see an example of generic SortedSet<T> class that stores elements using Add() method and iterates elements using for-each loop.

Output:

Ankit Irfan Peter tutor 

C# SortedSet<T> example 2

Let’s see another example of generic SortedSet<T> class that stores elements using Collection initializer.

Output:

Ankit Irfan Peter tutor 
Next TopicC# Stack

You may also like