Medium csharp

SortedDictionary — ordered keys #30

Problem

Iterate SortedDictionary keys in order.

Hints
  • Keys property in sorted order

Your practice code

Ready — edit the code above and click Run.

Solution

using System;

class Program
{
    static void Main()
    {
        using System.Collections.Generic;
        var map = new SortedDictionary<string, int> { ["b"] = 2, ["a"] = 1 };
        Console.WriteLine(string.Join(",", map.Keys));
    }
}

Try solving on your own first, then reveal the official answer.

Explanation

SortedDictionary keeps keys sorted—O(log n) operations.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details