0

I have a working line of code that retrieves the highest integer from a column in an ObservableCollection.

int highscore = dataAccess.GamePlayers.Max(t=> t.TotalScore);

I need a way to to retrieve the "next highest" integer from the same column. How could I achieve this with minimal code?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
astrox
  • 87
  • 7
  • In SQL it would be: "SORT DESCENDING" and "TOP 2". – Christopher May 09 '20 at 15:09
  • However, the question seems odd. If oyu got a Observaible Collection, you propably use WPF. If so, why would you need to math out the 2nd highest number? What is the purpose of that operation? Why is the stuff just not sorted in the Display, so the user can select it? – Christopher May 09 '20 at 15:10
  • 1
    Order by descending, skip the first number and get the next one – Pavel Anikhouski May 09 '20 at 15:13
  • 1
    Does this answer your question? [Find the second maximum number in an array with the smallest complexity](https://stackoverflow.com/questions/14810444/find-the-second-maximum-number-in-an-array-with-the-smallest-complexity) The same approach can be used for observable collection – Pavel Anikhouski May 09 '20 at 15:14
  • None of these helped. I am not using an array. My question clearly says ObservableCollection. – astrox May 09 '20 at 15:34
  • var sndHighest = dataAccess.GamePlayers.Where(x => x < highscore).Max(); – oRole May 09 '20 at 15:47

0 Answers0