Implementation of C# SortedSet class: Add() method
Program.cs
using System.Collections.Generic;

SortedSet<string> ss = new SortedSet<string>();
ss.Add("Cherry");
ss.Add("Apple");
ss.Add("Orange");
ss.Add("Mango");
ss.Add("Grapes");
ss.Add("Cherry");
ss.Add("Apple");
ss.Add("Pineapple");
ss.Add("Cherry");

foreach (string s in ss)
{
    Console.Write(s + " ");
}
Console.WriteLine("\nSize: " + ss.Count);
Output
kodingwindow@kw:~/csharp$ dotnet run
Apple Cherry Grapes Mango Orange Pineapple 
Size: 6
kodingwindow@kw:~/csharp$ 
Implementation of C# SortedSet class: Remove() and Clear() methods
Program.cs
using System.Collections.Generic;

SortedSet<string> ss = new SortedSet<string>();
ss.Add("Cherry");
ss.Add("Apple");
ss.Add("Orange");
ss.Add("Mango");
ss.Add("Grapes");
ss.Add("Cherry");
ss.Add("Apple");
ss.Add("Pineapple");
ss.Add("Cherry");

ss.Remove("Apple");
foreach (string s in ss)
{
    Console.Write(s + " ");
}
ss.Clear();
Console.WriteLine("\nSize: " + ss.Count);
Output
kodingwindow@kw:~/csharp$ dotnet run
Cherry Grapes Mango Orange Pineapple 
Size: 0
kodingwindow@kw:~/csharp$ 
Advertisement