December, 2006

  • Wriju's BLOG

    LINQ: Query vs Lambda Expression

    • 8 Comments

     

    LINQ is not just for the developers who used to write queries for databases but also for the Functional Programmers. So do not worry if you are not very comfortable with SQL kind of queries, we have a very nice option called “Lambda Expression”. Here I am going to demonstrate the scenario for both the options with a small example. This example has an array of integers and I am only retrieving the even numbers using the power of LINQ. Here we go

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Query;

    using System.Xml.XLinq;

    using System.Data.DLinq;

     

    namespace LINQConsoleApplication1

    {

        class Program

        {

            static void Main(string[] args)

            {

                int[] arrInt = {1,2,3,4,5,6,7,8,9,10};

     

                #region Place to change

                //Language Integrated Query

                var aa = from s in arrInt

                         where s % 2 == 0

                         select s;

                #endregion

     

                foreach (var item in aa)

                {

                    Console.WriteLine("{0}", item);

                }

                Console.ReadKey();

            }

        }

    }

     

    If you do not want to use the different approach of query for Language then you are free to use Lambda Expression. So just replace the #region area with the following code block results will be identical.

     

                #region Place to change

               

                //Lambda Expression

                var aa = arrInt.Where(s => s % 2 == 0);

     

                #endregion

     

    Output will look like

     

    Output

    =====================

    2

    4

    6

    8

    10

     

     

    Namoskar

     

  • Wriju's BLOG

    LINQ A Journey through Operators [Concat]

    • 2 Comments

     

    Imagine you have two arrays and you need to join them. Using LINQ it is as simple as mentioned

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Query;

    using System.Xml.XLinq;

    using System.Data.DLinq;

     

    namespace LINQ_Concat

    {

        class Program

        {

            static void Main(string[] args)

            {

     

                char[] alpha1 = {'A','B','C','D','E','F','G','H','I'};

                char[] alpha2 = {'J','K','L','M','N','O','P','Q','R'};

     

                var alphaAll = alpha1.Concat(alpha2);

     

                foreach(var al in alphaAll)

                {

                    Console.WriteLine(al);

                }

                Console.ReadKey();

            }

        }

    }

     

    Output will look like

     

    A

    B

    C

    D

    E

    F

    G

    H

    I

    J

    K

    L

    M

    N

    O

    P

    Q

    R

     

    Namoskar

     

  • Wriju's BLOG

    Anders and Chris McConnell on Channel9

    • 0 Comments

     

    Nice video on future on LINQ and they had a discussion on how it is possible to have api for programmers enabling the functional programming approach with the power of LINQ. Very nice to hear from Anders that LINQ has target for multi-core and mini-core processor.

     

    Watch the video http://channel9.msdn.com/Showpost.aspx?postid=260202

     

    Namoskar

     

  • Wriju's BLOG

    XLinq for RSS Feed

    • 2 Comments

     

    RSS 2.0 is popular in the world of BLOGGING. Let’s not discuss about what RSS does but how we can read RSS using XLinq (LINQ for XML). Here I have tried to read the RSS Feed of my BLOG and the URL for the RSS feed is http://blogs.msdn.com/wriju/rss.xml  

     

    This simple function pulls out the RSS XML details provided you know the structure.

     

    string GetOutput()

            {

                string strOut = string.Empty;

                string strFeed = "http://blogs.msdn.com/wriju/rss.xml";

     

                var feed = XDocument.Load(strFeed);

                var items = feed.Root.Element("channel").Elements("item");

                foreach(var item in items)

                    strOut+= item;

     

                return strOut;

            }

     

    Once you have the core XML in your hand using the .NET XML namespace you can play with it. It is really interesting.

     

    Welcome 2007!!!.

     

    Namoskar

     

  • Wriju's BLOG

    C#: Yesterday, Today, and Tomorrow: An Interview with Anders Hejlsberg, Part 2

    • 0 Comments

     

    A very interesting interview I found on the net. The discussion on C# and LINQ is in the Page 4.

     

    For full conversation please visit here.

     

    Other interviews with Anders

     

    Deep Inside C#: An Interview with Microsoft Chief Architect Anders Hejlsberg

     

    C#: Yesterday, Today, and Tomorrow: An Interview with Anders Hejlsberg, Part 1

     

    Namoskar

     

  • Wriju's BLOG

    Microsoft Exchange Server 2007 Released Today

    • 1 Comments

     

    The most awaited email system Microsoft Exchange Server 2007 got released today. This email server is with Office 2007 System and Windows Vista.

     

    Features like,

    Ø       Unified messaging with voice mail and fax messages.

    Ø       64-bit support

    Ø       Anti-spam management

    and lots more

     

    Enjoy Microsoft Exchange Server 2007 without installing. The Virtual Hard Disk is available for download at http://www.microsoft.com/downloads/details.aspx?FamilyId=6E6501F6-481A-4117-BC22-C745400BCDA0&displaylang=en

     

     

    Enjoy the UNIFIED power of messaging.

     

    Namoskar

     

Page 1 of 1 (6 items)