четверг, 21 октября 2010 г.

LINQ let Keyword (How did I miss that)

This is strange, because I've been working with LINQ for almost 2 years since (March 2006 CTP), and I've never noticed the new keyword "let" which is used inside LINQ queries to create temporarily variables.
check this out
var list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var query = from i in list
let j = i + 2
let k = j * j
select new { i, j, k };
As you can see the let keyword was used to create two new temp variables (j, k) which their values were calculated inside the query.
Looks nice, doesn't it

Комментариев нет: