LINQ Sort array element based on length

By Super Man

How you can sort array element based on their length.

string[] arr={"cherry","apple","mango","oranges","grapes"};

var z=arr.OrderBy(a=>a.Length);

foreach(var y in z)
{
Console.WriteLine(y);
}

LINQ Sort array element based on length  (571 Views)