Sunday, January 18, 2009

C#: Hello LINQ

Sample Code Exaplains how to use LINQ


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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

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)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}


Output for this code:

hello LINQ

No comments:

Post a Comment