string array sorted by the length each element : OrderBy : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » OrderBy »

 

string array sorted by the length each element








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

public class MainClass {
    public static void Main() {

        string[] words = { "abc", "bcd", "def" };

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

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

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» OrderBy