Add more sorting criteria with ThenByDescending in CSharp

Description

The following code shows how to add more sorting criteria with ThenByDescending.

Example


using System;//from  ww w  .j a  v a  2s  .  co  m
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {

        string[] presidents = {"ant", "arding", "arrison", "eyes", "over", "Jackson"};

        IEnumerable<string> items =
          presidents.OrderBy(s => s.Length).ThenByDescending(s => s);

        foreach (string item in items)
            Console.WriteLine(item);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ