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:

converting sql rank() linq, or alternative

linq query grouping , ranking

implementing rank on sql clause in c# linq


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -