Time for action – sorting a list of fruits

Follow the given steps:

  1. Copy the following code snippet as a query to LINQPad:
    string[] fruits = { "grape", "passionfruit", "banana", "apple", "orange", "raspberry", "mango", "blueberry" };
    
    //Sort the strings first by their length.
    var sortedFruits =  fruits.OrderBy(fruit => fruit.Length);
    sortedFruits.Dump("Sorted Fruits by Length");
  2. Run the query. You should get the following output:
    Time for action – sorting a list of fruits

    So you see the fruit names are sorted in ascending order of their length.

    Now, let's see what happens if we sort the elements alphabetically, maintaining this primary sorting as per their length.

  3. Change the query and paste the ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.