Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC#custom equality IComparerSingle-choice MCQ

You want a Dictionary keyed by case-insensitive strings AND you want each key's original casing preserved as stored. Which constructor argument achieves the case-insensitive lookup, and what is the gotcha?

var d = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); d["Hello"] = 1; d["HELLO"] = 2; Console.WriteLine(d.Count + " " + d.Keys.First());