//var sample= new { bottom=2, top=5,count=4};
var sample= new [] {2,3,4,5,6};
var q = from x in new int[]{0} //force desired behavior
    from i in sample
    from j in sample
    select Math.Pow(i,j);
q.Distinct().Count().Dump();
sample = new[]{2,3,4,5};
//q = from i in Enumerable.Range(sample.bottom, sample.top-sample.bottom+1)
//  from j in Enumerable.Range(sample.bottom, sample.top-sample.bottom+1)
//  select checked(System.Numerics.BigInteger.Pow((BigInteger)i,j));
q.Distinct().Count().Dump();
2nd answer is incorrect every time if the from x line is not there, or the resetting of the q variable is not done.(shown here commented out)
Original sample was an anonymous variable, but the array did it also.
var sample = new { bottom =2, top=5};
Is it related to this Scope of Linq Expressions defined in a loop - At issue: closing over loop variable ?
Why did putting a 1 item array on the top fix the closure?
 
     
     
    