0

i am using this code to order a list descending on numerical base

ItemsList.OrderByDescending(x => x.Views, new IntComparer());

public class IntComparer : IComparer<long>
{
    IComparer<long> Members;

    public int Compare(long x, long y)
    {
        return Math.Sign(x - y);
    }
}

but it doesn't order at all :S any help plz

MirooEgypt
  • 145
  • 1
  • 4
  • 10

2 Answers2

5

Enumerable.OrderByDescending is part of LINQ.

So it is not modifying the list, but it is creating new one. Use

ItemsList = ItemsList.OrderByDescending(x => x.Views, new IntComparer()).ToList();

or something similiar.

Euphoric
  • 12,645
  • 1
  • 30
  • 44
0

You should read this : http://msdn.microsoft.com/fr-fr/library/bb534861.aspx#Y1185 It seems that this method doesn't update the list, so you need to store the result.

List aList = ItemsList.OrderByDescending(x => x.Views, new IntComparer());

public class IntComparer : IComparer<long>
{
    IComparer<int> Members;

    public int Compare(long x, long y)
    {
        return Math.Sign(x - y);
    }
}

ItemsList = aList;
Golf Lima
  • 11
  • 2