Hello LINQ

Example. Hello LINQ
using System;
using System.Linq;

string[] greetings = {"hello world", "hello LINQ", "hello Apress"};

var items =
  from s in greetings
  where s.EndsWith("LINQ")
  select s;

foreach (var item in items)


The code in Listing 1-1 was added to a project created with the console application template in Visual Studio 2008. If one is not already present, you should add a using directive for the System.Linq namespace.

Running the previous code by pressing Ctrl+F5 outputs the following data to the console window:

hello LINQ

Get Pro LINQ: Language Integrated Query in C# 2008 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.