Mega Code Archive

 
Categories / C# Tutorial / LINQ
 

Query by string length with Linq

using System;   using System.Linq;   class Program   {       static void Main(string[] args)       {           string[] colors = {"Red", "Orange", "Yellow", "Green"};           var colorQuery = from color in colors                            where color.Length <= 5                            orderby color                            select color;           foreach (string s in colorQuery)               Console.WriteLine(s);           Console.WriteLine("\nPress any key to continue.");                  }   }