uses a compound orderby to sort a list of digits first by length of their name, and then alphabetically.

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {

        string[] digits = { "zero", "one", "two", "three"};

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

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

    


This entry was posted in LINQ. Bookmark the permalink.