0

I have a list populated with a custom data class, the list has column values string (Type) as well as double (Xo). I can successfully sort the list using two lines of code, is it possible to do the .Sort in one line?

        List.Sort((x, y) => x.Xo.CompareTo(y.Xo));
        List.Sort((x, y) => string.Compare(y.Type, x.Type));
Allstar
  • 429
  • 2
  • 9
  • 22

1 Answers1

0

You can use Linq OrderBy

var sorted = items.OrderBy(x => x.Xo).ThenBy(x => x.Type).ToList();
Flat Eric
  • 7,971
  • 9
  • 36
  • 45