Last Updated : 01 Feb, 2019
SortedSetclass represents the collection of objects in sorted order. This class comes under the
System.Collections.Genericnamespace.
Properties :SortedSet<T> mySortedSet = new SortedSet<T>();
Here,
mySortedSetis the name of the SortedSet and
Tis 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 13Example 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4