c# - Use linq to find index position, but take into account ties that depend on a value -
what best way sort value, find index of item rank, take account ties. index 5th place have 2 items 6th skipped , next iteration starts @ 7th. best way group , track index?
return teamtournamentresults .orderbydescending(t => t.rankingpoints) .select((item, index) => new { item = item, index = index }) .select(q => new teamsummaryresultsmodel { divisionranking = q.index + 1, rankingpoints= q.item.rankingpoints,
please, read comment question.
have @ example:
list<int> mi = new list<int>(){1,2,2,5,6,7,7,7,8,9,10,10}; var qry = mi .select(g=>new { number = g, rank = (from in mi i>g select i).count()+1 });
result:
number rank 1 12 2 10 2 10 5 9 6 8 7 5 7 5 7 5 8 4 9 3 10 1 10 1
other useful resources:
Comments
Post a Comment