Ordering words by word length, then by the alphabet - CSharp LINQ

CSharp examples for LINQ:order by

Description

Ordering words by word length, then by the alphabet

Demo Code



using System;/*w  w  w. j av a 2  s  . c  o 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 sortedNames =  from n in names orderby n.Length, n select n;
        foreach (var name in sortedNames)
        {
            Console.WriteLine("\t{0}", name);
        }
    }
}

Result


Related Tutorials