Wednesday, June 13, 2012

Learn by doing: Linq koans

You want to learn Linq, or increase your knowledge about it. Let’s introduce Linq koans. It allows you to learn LINQ by doing. Based on unit tests, you scroll down the class, fixing each test.(You have to replace the ‘___’ with the correct value.

Koans allow you to 'try out' aspects of a language while working in the language. In these koans, you just download the project, unzip it and open it in VS2010. Work with source the files in the following order:

1) LinqSynax.cs

2) LinqLambdaSyntax.cs

3) ExtendedLinqLamdbaSyntax.cs

As you change the blank (variable) to the correct answer and get the tests to pass, be sure to ask yourself after you get a green bar for each method, 'What did I just learn?'

A sample test:

public void LinqResults()
Microwavable result = (from x in ObjectsInMicrowave
where x.Name == "Ping Pong Ball"
select x).First();
Assert.AreEqual(___, result.Name);

No comments: