Pages
Calender
<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Blogroll
    Ajander Singh , Created On 9. June 2008, 16:08

    Using LINQ, we are able to create directly within the C# programming language entities called query expressions. These query expressions are based on numerous query operators that have been intentionally designed to look and feel very similar (but not quite identical) to a SQL expression. 

    Core LINQ assemblies:

     System.Core.dll

    Defines the types that represent the core LINQ API. This is the one assembly you must have access to. 

    System.Data.Linq.dll 

    Provides functionality for using LINQ with relational databases (LINQ to SQL). 

    System.Xml.Linq.dll 

    Defines a handful of types to integrate ADO.NET types into the LINQ programming paradigm (LINQ to DataSet). 

    System.Data.DataSetExtensions.dll 

    Provides functionality for using LINQ with XML document data (LINQ to XML). 


    First, A Taste of LINQ

        static void QueryOverStrings()
        {
            // Assume we have an array of strings.
            string[] currentVideoGames = {"Morrowind", "BioShock",
            "Half Life 2: Episode 1", "The Darkness",
            "Daxter", "System Shock 2"};
            // Build a query expression to represent the items in the array that have more than 6 letters.
            IEnumerable<string> subset = from g in currentVideoGames
            where g.Length > 6 orderby g select g;
            // Print out the results.
            foreach (string s in subset)
            Console.WriteLine("Item: {0}", s);
        }

     Query Expressions

            from itemName in srcExpr
            join itemName in srcExpr on keyExpr equals keyExpr
            (into itemName)?
            let itemName = selExpr
            where predExpr
            orderby (keyExpr (ascending | descending)?)*
            select selExpr
            group selExpr by keyExpr
            into itemName query-body




    Ajander Singh , Created On 27. May 2008, 16:57

    C# supports the ability to handle events “inline” by assigning a block of code statements directly to an event, rather than building a stand-alone method to be called by the underlying delegate.


    ArgumentsToProcess => StatementsToProcessThem

    static void LambdaExpressionSyntax()
    {
    // Make a list of integers.
    List<int> list = new List<int>();
    list.AddRange(new int[] { 20, 1, 4, 8, 9, 44 });
    // Now, use a C# 2008 lambda expression.
    List<int> evenNumbers = list.FindAll(i => (i % 2) == 0);
    Console.WriteLine("Here are your even numbers:");
    foreach (int evenNumber in evenNumbers)
    {
    Console.Write("{0}\t", evenNumber);
    }
    Console.WriteLine();
    }


    Processing Arguments Within Multiple Statements

    // Now process each argument within a group of
    // code statements.
    List<int> evenNumbers = list.FindAll((i) =>
    {
    Console.WriteLine("value of i is currently: {0}", i);
    bool isEven = ((i % 2) == 0);
    return isEven;
    });