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 live online training, plus books, videos, and digital content from nearly 200 publishers.