The
SortedSet<> class represents a collection of objects that are maintained
in sorted order.
This is an ordered
set collection.so C# SortedSet class can be used to store, remove or view
elements. It maintains ascending order and does not store duplicate elements.
Creation of the
SortedSet<>
SortedSet<string> sortedset = new
SortedSet<string>();
SortedSet<int> sortedset1 = new
SortedSet<int>();
|
Example
using System;
using System.Collections.Generic;
public class SortedSetExample
{
public static void Main(string[] args)
{
// Create a set of strings
var names = new SortedSet<string>();
names.Add("Nitin Kumar ");
names.Add("Rahul Chauhan");
names.Add("Prashant Kumar");
names.Add("Neelam Chauhan");
names.Add("Ankit gupta");//will not be added
// Iterate SortedSet elements using foreach loop
foreach (var name in names)
{
Console.WriteLine(name);
}
Console.Read();
}
}
|
Output