Sort array elements on the basis their lengths and then alphabetically

Ddd
Posted by Ddd under LINQ category on | Points: 40 | Views : 1662
//Sort array elements on the basis their lengths and then alphabetically

using System;
using System.Linq;

class srt
{
static void Main()
{
string[] arr={"cherry","apple","mango","oranges","grapes"};
var z=arr.OrderBy(a=>a.Length).ThenBy(b=>b);
Console.WriteLine("this is the order");
foreach(var y in z)
{
Console.WriteLine(y);
}
}
}
//The logic:

//1st 5 character elements , then 6 character elements, then 7 character elements will be displayed
// then the 5,6,7 character elements will be sorted alphabetically in their respective groups

Comments or Responses

Login to post response