Getting Started with Standard Query Operators

 

To see language-integrated query at work, we'll begin with a simple C# 3.0 program that uses the standard query operators to process the contents of an array:

using System;
using System.Linq;
using System.Collections.Generic;

class app {
  static void Main() {
    string[] names = { "Burke", "Connor", "Frank",
                       "Everett", "Albert", "George",
                       "Harris", "David" };

    IEnumerable<string> query = from s in names
                               where s.Length == 5
                               orderby s
                               select s.ToUpper();

    foreach (string item in query)
      Console.WriteLine(item);
  }
}

If you were to compile and run this program, you'd see this as output:

BURKE
DAVID
FRANK

To understand how language-integrated query works, we need to dissect the
 first statement of our program.

IEnumerable<string> query = from s in names
                           where s.Length == 5
                           orderby s
                           select s.ToUpper();