OrderBy: prints an alphabetically sorted version of a string array

image_pdfimage_print
   
 

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

public class MainClass {
    public static void Main() {

        string[] words = { "C", "a", "b" };

        var sortedWords =
            from w in words
            orderby w
            select w;

        Console.WriteLine("The sorted list of words:");
        foreach (var w in sortedWords) {
            Console.WriteLine(w);
        }
    }
}

    


This entry was posted in LINQ. Bookmark the permalink.