C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
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> exampleLet's see an example of generic SortedSet<T> class that stores elements using Add() method and iterates elements using for-each loop. using System; using System.Collections.Generic; public class SortedSetExample { public static void Main(string[] args) { // Create a set of strings var names = new SortedSet Output: Ankit Irfan Peter Sonoo C# SortedSet<T> example 2Let's see another example of generic SortedSet<T> class that stores elements using Collection initializer. using System; using System.Collections.Generic; public class SortedSetExample { public static void Main(string[] args) { // Create a set of strings var names = new SortedSet Output: Ankit Irfan Peter Sonoo
Next TopicC# Stack
|