Given the following data:
List<Country> countries = new List<Country>();
countries.Add(new Country{ Name = "USA", population=500000, Year=2012 });
countries.Add(new Country{ Name = "USA", population=300000, Year=2002 });
countries.Add(new Country{ Name = "USA", population=250000, Year=1992 });
countries.Add(new Country{ Name = "USA", population=20000, Year=1982 });
countries.Add(new Country{ Name = "India", population=1500000, Year=2012 });
countries.Add(new Country{ Name = "India", population=1000000, Year=2002 });
countries.Add(new Country{ Name = "India", population=50000, Year=1982 });
countries.Add(new Country{ Name = "India", population=80000, Year=1992 });
countries.Add(new Country{ Name = "Germany", population=100000, Year=2012 });
countries.Add(new Country{ Name = "Germany", population=400000, Year=2002 });
countries.Add(new Country{ Name = "Germany", population=60000, Year=1992 });
countries.Add(new Country{ Name = "Germany", population=4000, Year=1982 });
countries.Add(new Country{ Name = "UK", population=450000, Year=2002 });
countries.Add(new Country{ Name = "UK", population=50000, Year=1992 });
countries.Add(new Country{ Name = "UK", population=3000, Year=1982 });
I want to order the countries by the largest population for a given year, but then display all the years for that country before moving on to the next country.
E.g.
2012 - the population order would be India, USA, UK, Germany. So I would like the data to be ordered by all India data, all USA data, all UK data and then Germany.
2002 - the population order would be India, USA, Germany and then UK. UK is last because it has no 2002 data.
I want to achieve this using LINQ, although I've used LINQ in the past I'm struggling to get my head around this. Any help would be much appreciated.