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

SortedDictionary<long, string> sd = new SortedDictionary<long, string>();
sd.Add(25622348991, "Edward Parkar");
sd.Add(25622348990, "Donald Taylor");
sd.Add(25622348992, "Ryan Bakshi");
sd.Add(25622348989, "James Moore");

foreach (KeyValuePair<long, string> kv in sd)
{
    Console.WriteLine("Account No: {0}, Name: {1}", kv.Key, kv.Value);
}
Console.WriteLine("Size: " + sd.Count);
Output
kodingwindow@kw:~/csharp$ dotnet run
Account No: 25622348989, Name: James Moore
Account No: 25622348990, Name: Donald Taylor
Account No: 25622348991, Name: Edward Parkar
Account No: 25622348992, Name: Ryan Bakshi
Size: 4
kodingwindow@kw:~/csharp$ 
Implementation of C# SortedDictionary class: Keys and Values properties
Program.cs
using System.Collections.Generic;

SortedDictionary<long, string> sd = new SortedDictionary<long, string>();
sd.Add(25622348991, "Edward Parkar");
sd.Add(25622348990, "Donald Taylor");
sd.Add(25622348992, "Ryan Bakshi");
sd.Add(25622348989, "James Moore");

SortedDictionary<long, string>.KeyCollection kc1 = sd.Keys;
foreach (long accno in kc1)
{
    Console.WriteLine("Account No: " + accno);
}

SortedDictionary<long, string>.ValueCollection kc2 = sd.Values;
foreach (string name in kc2)
{
    Console.WriteLine("Name: " + name);
}
Output
kodingwindow@kw:~/csharp$ dotnet run
Account No: 25622348989
Account No: 25622348990
Account No: 25622348991
Account No: 25622348992
Name: James Moore
Name: Donald Taylor
Name: Edward Parkar
Name: Ryan Bakshi
kodingwindow@kw:~/csharp$ 
Implementation of C# SortedDictionary class: Remove() and Clear() methods
Program.cs
using System.Collections.Generic;

SortedDictionary<long, string> sd = new SortedDictionary<long, string>();
sd.Add(25622348991, "Edward Parkar");
sd.Add(25622348990, "Donald Taylor");
sd.Add(25622348992, "Ryan Bakshi");
sd.Add(25622348989, "James Moore");

sd.Remove(25622348989);
foreach (KeyValuePair<long, string> kv in sd)
{
    Console.WriteLine("Account No: {0}, Name: {1}", kv.Key, kv.Value);
}

sd.Clear();
Console.WriteLine("Size: " + sd.Count);
Output
kodingwindow@kw:~/csharp$ dotnet run
Account No: 25622348990, Name: Donald Taylor
Account No: 25622348991, Name: Edward Parkar
Account No: 25622348992, Name: Ryan Bakshi
Size: 0
kodingwindow@kw:~/csharp$ 
Advertisement