What’s the best way (*) to get the keys of a Dictionary<string, object> into a string[] (sorted alphabetically)?
Example:
var d = new Dictionary<string, int>();
d.Add("b", 1);
d.Add("f", 2);
d.Add("a", 3);
string[] sortedKeys = ...;
// sortedKeys should contain ["a", "b", "f"]
(*) what I mean with “best way” is probably: it should be easy to write and read, but should still result in good performance
It depends what you mean by “best” – but I’d use:
Slightly more efficient but less fluent: