Why it is possible to use this:
from r1 in Enumerable.Range(1, 10)
join q1 in Enumerable.Range(1, 20) on r1 equals q1
select r1;
but not possible to use this:
from r1 in Enumerable.Range(1, 10)
let q = Enumerable.Range(1, 20)
join q1 in q on r1 equals q1
select r1;
The MSDN documentation on let clause lacks some details.
Update:
I’ve just tried to make the expression more clearly readable. In my situation I have some methods chaining that I would like to put to the let clause. Otherwise the join clause became too monstrous. As it is not possible to use the let clause (as Jon mentioned) I’ve introduced the outer variable, here:
IEnumerable<int> q = Enumerable.Range(1, 10);
from r1 in Enumerable.Range(1, 10)
join q1 in q on r1 equals q1
select r1;
Unlike
SelectMany, aJoinclause can’t depend on the “current” value of the other range variables – so this will work:… but the join won’t.
If you could elaborate on what you’re trying to do, we may be able to help more.