I have a dictionary in C# like
Dictionary
and I want to sort that dictionary in place with respect to keys (a f
While Dictionary is implemented as a hash table, SortedDictionary is implemented as a Red-Black Tree.
If you don't take advantage of the order in your algorithm and only need to sort the data before output, using SortedDictionary would have negative impact on performance.
You can "sort" the dictionary like this:
Dictionary<string, int> dictionary = new Dictionary<string, int>();
// algorithm
return new SortedDictionary<string, int>(dictionary);