Ordering in descending order - CSharp LINQ

CSharp examples for LINQ:order by

Description

Ordering in descending order

Demo Code



using System;//from   w ww .j a  v a  2s.  co m
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {

        string[] names = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

        var namesInDescendingLengthGroups = from n in names orderby n.Length descending, n select n;
        foreach (var name in namesInDescendingLengthGroups)
        {
            Console.WriteLine("\t{0}", name);
        }
    }
}

Result


Related Tutorials