Sunday, September 4, 2011

Dance with LINQ

For the first time I saw LINQ syntax I told to myself what the...
How in the world I can understand and write LINQ syntax easily. What is LINQ in first place? Is there any value for me to learn this. Guess what I started to think in ways to use it. Then I found it very handy.
In next posts I will try to teach you LINQ how to use it and how to understand exactly what are you doing and what LINQ can offer you.
Let's start with what is LINQ. after all if you want to start dancing with it you need to know your partner otherwise your dance will not be that much sexy! eventhough you are a good dancer.

LINQ is microsoft solution to query different sources like objects, XML, Dataset, SQL and entities easily with less code. However it is not just to query data. You can use LINQ to iterate items and even change thier types and use it to sort and etc.

at this stage please do not worry about the code in future posts I will talk about C# 3.0 futures so you will understand exactly how LINQ works. in the following example a list of string numbers are changing to int and also they are get sorted. I am sure you see what a nice functionality it it.

string[] mynums = {"34","020","3","16"};
int[] nums = mynums.Select(s=> Int32.Parse(s)).OrderBy(s=>s).ToArray();
foreach (int n in nums)
Console.WriteLine(n);

In next couple of posts I will talk about C# enhancements for LINQ so when we start LINQ then you have a better idea what is going on.

Hopefully you liked the first dance class with LINQ.

Please keep me updated.