Query string and where by string length in CSharp

Description

The following code shows how to query string and where by string length.

Example


using System;//from w  ww . j av  a 2 s.  c  om
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            string[] currentVideoGames = {"test", "this is a test", "asdf", "game 1","game 2", "game 3"};
            var subset = from g in currentVideoGames 
                         where g.Length > 6 
                         orderby g 
                         select g;
            foreach (var s in subset)
                Console.WriteLine("Item: {0}", s);
        }
    }

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ