Query by string length with Linq : where « LINQ « C# / CSharp Tutorial





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.");
          
      }
  }










22.9.where
22.9.1.Where Prototype
22.9.2.To remove all vowels from a string.
22.9.3.A Query Using the Standard Dot Notation Syntax
22.9.4.Query Using the Query Expression Syntax
22.9.5.Query string value by String.StartsWith
22.9.6.Where clause with string method and return IEnumerable object
22.9.7.Query with an Exception
22.9.8.Use string method in where clause
22.9.9.where clause
22.9.10.Use where to filer object list
22.9.11.Use && in where clause
22.9.12.Filtered: prints the name of each element of an integer array that is less than 5
22.9.13.prints strings where each element has the second letter 'i'.
22.9.14.Two where clauses
22.9.15.Using where clause in a while loop
22.9.16.Assign the loop variable to another variable declared inside the statement block
22.9.17.Filter string by its length
22.9.18.Display Products With Unknown Price
22.9.19.Get upper case chars
22.9.20.Query by string length with Linq
22.9.21.Query for filtering numbers
22.9.22.Filter by Make and Speed
22.9.23.LINQ Method Syntax
22.9.24.Simple method based query
22.9.25.Search Customers by first name
22.9.26.LINQ query to get strings starting with s
22.9.27.Ice Creams with price less than 10
22.9.28.Use function in where clause
22.9.29.Modifying Where Behavior