Use function in where clause in CSharp

Description

The following code shows how to use function in where clause.

Example


using System;/*ww w  . j a v  a2  s . c o  m*/
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


public class MainClass{

   public static void Main(string[] args){   
         String[] QueryString = { "One", "Two", "Three", "Four", "Five",
              "Six", "Seven", "Eight", "Nine", "Ten" };

         var ThisQuery = from StringValue in QueryString 
            let IndexValue = StringValue.Substring(0, 1)
            where Convert.ToChar(IndexValue) > 'F'
            orderby IndexValue
            select new {StringValue, IndexValue};

         foreach (var ThisValue in ThisQuery)
            Console.WriteLine(ThisValue.IndexValue + " - " + ThisValue.StringValue);



   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ