Use of let Keyword in LINQ

Posted by Sksingh under LINQ category on | Points: 40 | Views : 2723
Let keyword provides facility to declare a temporary variable inside the Linq Query.
We can assign the result of manipulation to temporary variable inside query and we can use that temporary variable for another manipulation.

In below example let keyword hold the variable name "pow" and calculated value get manupulate in LINQ query itself.

private static void UseOfLetKeyword()
int[] arr = { 1, 2, 3, 4, 5 };
var Result = from i in arr
let pow = Math.Pow(i, 3) // get the power of 3 for each numbers in arr and consider only those values which result will be greater than 10
where pow > 10
select pow;

foreach (int i in Result)



Comments or Responses

Posted by: Akiii on: 12/16/2011 Level:Bronze | Status: [Member] | Points: 10
nice one Sunil

Thanks and Regards
Posted by: Samarmir on: 12/16/2011 Level:Starter | Status: [Member] | Points: 10
Thanks for this short and good example
Please do not be shy to show more examples :)
Posted by: Sksingh on: 12/16/2011 Level:Starter | Status: [Member] | Points: 10
Thanks Akiii & Samarmir..

Login to post response