-1

I have a list of objects in which each object has a property called "Frequency" and I want to be able to pick the top 10 objects that have the highest frequencies.

I saw some solutions that are kind of similar to what I am looking to solve using LINQ so any help is appreciated.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
kristof
  • 99
  • 1
  • 3
  • 11
  • Use OrderBy (either ascending or descending) and then Take(10). – jdweng Sep 05 '18 at 11:08
  • 4
    `var youwant=list.OrderByDescending(x=>x.Frequency).Take(10);` – Tim Schmelter Sep 05 '18 at 11:08
  • 2
    Welcome to stackoverflow kristof. I would suggest you to check the help center because it would help you to avoid asking questions already answered https://stackoverflow.com/questions/4872946/linq-query-to-select-top-five?s=1|101.2250 and make question of better quality, providing a [mcve] which could have better answers. – Cleptus Sep 05 '18 at 11:25
  • 1
    @Reniuz please do note it is a new contributor, the "we expect here some effort" is a bit rude. – Cleptus Sep 05 '18 at 11:26

1 Answers1

15

You can order the list by descending Frequency and then take the first 10 like this:

var top10 = objectList.OrderByDescending(o => o.Frequency).Take(10);
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35