I tried using SortedDictionary to store some of my data from a file, but got a really strange bunch of key duplication exceptions. I came up with the following code example that reproduces my problem:
var dict = new SortedDictionary<string, string>();
dict.Add("Æ", "qwerty");
Console.WriteLine(dict["AE"]);
dict.Add("AE", "");
This code in .NET Fiddle
This does not happen for a regular dictionary, although I finally decided to use it. But I still wonder why this is a problem for sorting? Unfortunately, I couldn’t answer the question myself (I got a lot of noise related to AES), and I can’t debug the SortedDictionary code, despite the fact that MS recently opened some kind of .NET source code.
This class seems to implicitly run some string preprocessing / normalization function, but I just can't believe this is the real reason.
Any ideas why this is happening? Thanks in advance!
source
share