meodudang 0 Newbie Poster

HI all,
I'm a newbie of C#.
As I have read, there is useful concept "delegate function".
I don't waste your time anymore,
I wanna sort a List<int> with this criterion:
_ Items at odd index are sorted with descending order.
_ Items at even index are sorted with ascending order.
It's no problem if I use normal way to make the code. But I wanna try in delegate function so I use List<T>.Sort(GenericComparison). I've got problem with the comparison function:

sl.Sort(delegate(int a, int b)
{                
  if (((sl.IndexOf(a) % 2) == 0) && ((sl.IndexOf(b) % 2) == 0) 
    return a.CompareTo(b);
  if (((sl.IndexOf(a) % 2) == 1) && ((sl.IndexOf(b) % 2) == 1) 
    return b.CompareTo(a);
  return 0;
});

Did i do something wrong? pls help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.