Query expression syntax

C# provides another syntax for writing queries, called query expression syntax.

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        string[] names = { "C", "Java", "C#", "Javascript" };

        IEnumerable<string> filteredNames = from n in names
                                            where n.Contains("a")
                                            select n;
        foreach (string name in filteredNames)
            Console.WriteLine(name);

    }
}
  

The output:


Java
Javascript
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.