Created
June 28, 2011 23:59
-
-
Save sdether/1052544 to your computer and use it in GitHub Desktop.
Better not rely on this behavior...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Building_dictionary_from_ordered_list_preserves_key_order() { | |
var d = new Dictionary<string, string>() { | |
{"x", "x"}, | |
{"a","a"}, | |
{"g","g"}, | |
{"b","b"} | |
}; | |
Console.WriteLine("original order: " + string.Join("&", d.Select(x => x.Key + "=" + x.Value).ToArray())); | |
d = d.OrderBy(x => x.Key, StringComparer.Ordinal).ToDictionary(k => k.Key, v => v.Value); | |
Console.WriteLine("after sort rebuild: "+string.Join("&", d.Select(x => x.Key + "=" + x.Value).ToArray())); | |
} | |
>>>>>>>>> | |
original order: x=x&a=a&g=g&b=b | |
after sort rebuild: a=a&b=b&g=g&x=x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment