There are so many new things to try out so I´m going crazy. But I decided to try out Linq (Language Integrated Query) first.
I got really inspired starting with this while watching the Channel 9 interview with Ander Hejlsberg.
Who haven´t dreamt about writing SQL direct in your C# with CLR debugging instead of creating a string with the SQL or using stored Procedures. Now you are able to use CLR data types and get all the functionality in .NET while filtering the data!
If you want to use Linq you need to download the Tech Preview from MSDN. It will be integrated in Visual Studio 2005 so you can easilly start building applications using Linq + C# or VB.NET.
Here is an example I wrote in 2 minutes just to see if it worked correctly:
using System;
using System.Collections.Generic;
using System.Text;
using System.Query;
using System.Xml.XLinq;
using System.Data.DLinq;
namespace LINQTest
{
class Program
{
static void Main(string[] args)
{
int[] iNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var expr = from s in iNumbers
where s > 3 && s < 7
orderby s
select s;
foreach (int item in expr)
Console.WriteLine(item);
Console.ReadLine();
}
}
}
This example is selecting the numbers from a collection where the value is between 4 and 6.
The output should look like this:
4
5
6
The fact that you can actually run queries against all collections that inherits IEnumerable is so damn cool! You can save a lot of code using this since you don´t need to run nested loops that checks everything.
I´m going to write about DLinq (how to use Linq while querying relational data) and XLinq (how to run queries against XML).
For further reading:
MSDN LINQ Home
LINQ Blogger RSS Feed
Download the Tech Preview
View 101 LINQ samples online