Use Contains in LINQ query in CSharp

Description

The following code shows how to use Contains in LINQ query.

Example


using System;/*www .  j  a  v a  2  s. c o  m*/
using System.Collections.Generic;
using System.Linq;

class LinqDemo {
    static void Main() {
        string[] names = { "Java", "Pascal", "Grovvy", "java2s.com" };

        IEnumerable<string> query =
          from n in names
          where n.Contains("a")     
          orderby n.Length          
          select n.ToUpper();       

        foreach (string name in query) 
            Console.Write(name + "/");
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ