Order by string length in CSharp
Description
The following code shows how to order by string length.
Example
using System;// ww w .j av a2s .c o m
using System.Collections.Generic;
using System.Linq;
public class MainClass {
public static void Main() {
string[] names = { "Java", "Pascal", "GWT Vaadin", "Pass" };
IEnumerable<string> query = names.Where(n => n.Contains("a"))
.OrderBy(n => n.Length)
.Select(n => n.ToUpper());
foreach (var item in query)
{
Console.WriteLine(item);
}
}
}
The code above generates the following result.