I am trying to do a sort on dictionary
class Program {
static void Main()
{
// Example dictionary.
var dictionary = new Dictionary<string, int>(5);
dictionary.Add("cat", 3);
dictionary.Add("dog", 1);
dictionary.Add("mouse", 0);
dictionary.Add("elephant", 2);
dictionary.Add("bird", 4);
var items = from pair in dictionary
orderby pair.Value ascending
select pair;
// Display results.
foreach (KeyValuePair<string, int> pair in items)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
items = from pair in dictionary
orderby pair.Value descending
select pair;
} }
The result is
mouse
dog
elephant
cat
bird
But I need to exclude the first pair to sort the rest and to get this result
cat
mouse
dog
elephant
bird
Can I do anything from here?
var items = from pair in dictionary
orderby pair.Value ascending
select pair;