//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};
這是否與此Scope of Linq Expressions defined in a loop - At issue: closing over loop variable?
爲什麼在頂部放置一個物品數組修復了封口?
你的問題與懶惰評估不關閉。 – Hogan
難道不是兩個?從某種意義上說,這是懶惰的評價,其中一部分是熱切評價的,另一部分是懶洋洋地評價的。這對我來說是一個閉幕,一個不是。 – Maslow
這似乎同意我們倆。 http://stackoverflow.com/questions/428617/what-are-closures-in-net – Maslow