//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();
from x line
如果不存在,或者未完成变量的重置,则每次第二个答案都是不正确的q
。(此处显示已注释掉)
原始样本是一个匿名变量,但数组也这样做了。
var sample = new { bottom =2, top=5};
它是否与循环中定义的 Linq 表达式范围有关 - 有问题:关闭循环变量?
为什么将 1 项数组放在顶部修复了闭包?