C# | How to create a SortedSet Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. 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: SortedSet<T> mySortedSet = new SortedSet<T>(); Here, mySortedSet is the name of the SortedSet and T is Type Parameter. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP // C# code to create a SortedSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of integers SortedSet<int> mySortedSet = new SortedSet<int>(); // Adding elements in mySortedSet for (int i = 1; i <= 6; i++) { mySortedSet.Add(2 * i + 1); } // Displaying elements in mySortedSet Console.WriteLine("The elements in mySortedSet are : "); // Displaying the element in mySortedSet foreach(int i in mySortedSet) { Console.WriteLine(i); } } } Output: The elements in mySortedSet are : 3 5 7 9 11 13 Example 2: CSHARP // C# code to create a SortedSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a SortedSet of strings SortedSet<string> mySortedSet = new SortedSet<string>(); // Adding elements in mySortedSet mySortedSet.Add("H"); mySortedSet.Add("E"); mySortedSet.Add("L"); mySortedSet.Add("L"); mySortedSet.Add("O"); // Displaying elements in mySortedSet Console.WriteLine("The elements in mySortedSet are : "); // Displaying the element in mySortedSet foreach(string str in mySortedSet) { Console.WriteLine(str); } } } Output: The elements in mySortedSet are : E H L O Comment More infoAdvertise with us Next Article C# SortedSet Class S Sahil_Bansall Follow Improve Article Tags : Misc C# CSharp-Generic-SortedSet CSharp-Generic-Namespace Practice Tags : Misc Similar Reads C# | How to create a SortedList SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. Properties of SortedList: Internally the object of SortedList maintains two arr 2 min read C# | How to get a subset in a SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.GetViewBetween(T, T) method is used to return a view of a subset in a SortedSet<T>. Properties: In C#, SortedSet class can be used to store, remov 2 min read C# | Add element to SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet.Add(T) Method is used to add an element to the set and returns a value that specify if it was successfully added or not. Properties: In C#, SortedSet class 2 min read C# | Union of SortedSet to a collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.UnionWith(IEnumerable<T>) method is used to modify the current SortedSet<T> object so that it contains all elements that are present in either 2 min read C# SortedSet Class SortedSet class in C# represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace.In C#, the 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 5 min read C# | Intersection of SortedSet with a collection SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.IntersectWith(IEnumerable<T>) method is used to modify the current SortedSet<T> object so that it contains only elements that are also in a spe 2 min read Like