Reverse Sorting with IComparable
If your User
class can be changed to sort in reverse order, you can try other answers which suggests modifying CompareTo
method. Otherwise try the following.
users.Sort();//Sort normally
users.Sort((x, y) => y.CompareTo(x));//Reverse sort
If you want to reverse the order, just reverse the comparison:
public int CompareTo(User b)
{
return b.total.CompareTo(this.total);
}