Total Pageviews

Search This Blog

Monday, February 4, 2008

Getting Started with my first LINQ program

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// The Three Parts of a LINQ Query:
// 1. Data source.
int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
// 2. Query creation.
// numQuery is an IEnumerable
var numquery =
from num in numbers
where (num % 2) == 0
select num;

//3. Query Execution
foreach (int num in numquery)
{
Console.Write("{0,1}", num);
}
}
}
}

No comments: