0

I am currently working on a little program for myself, connected to LastFM. Here I can fetch a whole list artists, played in the current week. This is how I first fetch the artists played and store them into a list:

WeeklyArtistChart WeeklyArtists = user.GetWeeklyArtistChart();
//WeeklyArtistChart is a list

Now, let's say each entry in WeeklyArtists[i].Artist has a property named 'Playcount'. I want to sort my list based on that property in descending order, only problem is, I have no idea how!

Your help would be greatly appreciated!

Infernus
  • 53
  • 1
  • 2
  • 8

1 Answers1

2

You can use LINQ and Enumerable.OrderByDescending:

var sortedArtists = WeeklyArtists.OrderByDescending(a => a.Artist.Playcount);

If you need a copy of the list with this order, you need to call ToList:

WeeklyArtists = sortedArtists.ToList();
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939