I have a dictionary which holds strings as keys and Lists as values. Imagine you have Olympic Games where the keys are different countries and the values in each list are for example number of participants, number of sports, gold medals, silver medals, etc. So if I want to sort the countries by gold medals and say gold medals is the second entry in each list I would want something like this:
var countryRankings = new Dictionary<string, List<int>>(); countryRankings.Add(country, new List<int>() {numberOfParticipants, numberOfWins }); //some more country data follows countryRankings.OrderByDescending(pairs => pairs.Value[1]); The last bit is not rejected by VisualStudio but is not working as expected. The dictionary is not sorted.When I think about it it's better to create class country with different properties and then sort with Lambda in the way OrderBy(c => c.goldMedals) but is there a way to do this with nested inside a dictionary List ?