Skip to content

Instantly share code, notes, and snippets.

@sdether
Created June 28, 2011 23:59
Show Gist options
  • Save sdether/1052544 to your computer and use it in GitHub Desktop.
Save sdether/1052544 to your computer and use it in GitHub Desktop.
Better not rely on this behavior...
[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