Considering following code:
class Results
{
public int playerId;
public int score;
public int section;
public int position;
public Results(int _playerId, int _score, int _section)
{
playerId = _playerId;
score = _score;
section = _section;
}
}
public void RankMyResults()
{
List<Results> myResultList = new List<Results>();
myResultList.Add(new Results(1,232, 1));
myResultList.Add(new Results(2,213, 1));
// Add a lot of more results
// Iteriate over the items to set the position
}
I want to set position 1 for the highest score in each section, position 2 for second highest and so on.
Also if two people have the same score the positions should look like this
Position Score PlayerId Section
1 135 23 1
1 135 43 1
3 131 45 1
As in this example it will skip position 2.
Is there a nice way to use LINQ to do this or for example using some Select, Sorting functionality from the List Object?
My own solution iterate over the list is not good at all!
I wrote these extension methods just a few days ago:
You can use them as follows:
The difference between
RankByandDenseRankByis thatRankBycreates “gaps” (e.g. 1,1,3,3,3,6…) whereasDenseRankBydoes not (1,1,2,2,2,3…)