Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Monday, October 29, 2012

LINQ Sample

There are three parts in any LINQ Query
a. Data Source  - Could be an array collection, Database TAble, Object Collection, Etc...
b. Creating Query - The LINQ Query Creation
c. Executing Query - Query created doesn't get executed immedietly. It gets executed only during enumeraing the result

Sample

class SampleLINQ
{       
    static void Main()
    {

        //  1. Getting Data source.
        int[] intarray = new int[5] { 3, 1, 9, 63, 17};

        // 2. Query creation.
        var intenumQuery =
            from num in intarray
            where (num % 3) == 0
            select num;

        // 3. Query execution.
        foreach (int intvalue in intenumQuery )
        {
            Console.Write("{0,1} ", num);
        }
    }
}