LINQ ThenBy Query Operator

By Peter Bromberg

Performs a subsequent ordering of the elements in a sequence in ascending order. This member is overloaded. See the overload list for details.

public void LinqThenBy()
{
    string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

    var sortedDigits =
        from d in digits
        orderby d.Length, d
        select d;

   Console.WriteLine("Sorted digits:");
    foreach (var d in sortedDigits)
    {
       Console.WriteLine(d);
    }
}Result

Sorted digits:
one
six
two
five
four
nine
zero
eight
seven
three

LINQ ThenBy Query Operator  (707 Views)