Return to Snippet

Revision: 56850
at April 19, 2012 05:46 by denakitan


Updated Code
// 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<int>
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);
}

Revision: 56849
at April 19, 2012 05:42 by denakitan


Initial Code
// 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<int>
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);
}

Initial URL
http://msdn.microsoft.com/en-us/library/bb397906.aspx

Initial Description
Snippet to illustrate the three actions that happen in all LINQ query operations.

Initial Title
.NET - LINQ - C# - Basics - Examples - The Three Parts of a LINQ Query

Initial Tags
query, Net, c#

Initial Language
C#