The first step in understanding what is going on here is understanding how the query expression is expressed. According to specification:
from x1 in e1 from x2 in e2 select v
translates to
e1.SelectMany(x1 => e2, (x1, x2) => v)
This is incredibly important to understand. The result from x1 in e1 from x2 in e2 select v is a request for e1 , regardless of e1 ; it is fixed, period.
Now, here is the problem. Look at your request.
var q = from i in sample from j in sample select Math.Pow(i, j)
The sample value at the time of constructing the query is a reference to the result of the array creation expression new[] { 2, 3, 4, 5, 6 } . Let e1 be a reference to the result of this array creation expression. Then the query will look like this:
e1.SelectMany(i => sample, (i, j) => Math.Pow(i, j));
This is a fixed period, regardless of what you reassign to sample . That is, you should think about
var sample = new[] { 2, 3, 4, 5, 6 } var q = from i in sample from j in sample select Math.Pow(i, j)
a
var sample = new[] { 2, 3, 4, 5, 6 }; var e1 = sample; var q = e1.SelectMany(i => sample, (i, j) => Math.Pow(i, j));
Now the sample closed, so after you assign a new value to sample , you will see a different query result. But no matter what , e1 remains fixed as the result of the array creation expression new[] { 2, 3, 4, 5, 6 } .
However, when you start with a request
var q = from x in new int[] { 0 } from i in sample from j in sample select Math.Pow(i, j)
now the request is translated into
int[] e1 = new int[] { 0 }; var q = e1.SelectMany( x1 => sample.SelectMany(i => sample, (i, j) => Math.Pow(i, j) );
and now sample is fixed as a sequence for i and j , but e1 fixed.