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.
Example 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)
{
Console.WriteLine(i.ToString());
}
}
output
======
27
64
125