按照此鏈接:http://msdn.microsoft.com/en-us/library/bb397906.aspx的LinQ:查詢時將執行
namespace Linq
{
class IntroToLINQ
{
static void Main()
{
// The Three Parts of a LINQ Query:
// 1. Data source.
int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
// 2. Query creation.
// numQuery is an IEnumerable<int>
var numQuery =
from num in numbers
where (num % 2) == 0
select num;
// 3. Query execution.
foreach (int num in numQuery)
{
Console.Write("{0,1} ", num);
}
}
}
}
它說,查詢將不會被exeucted,直到數據通過foreach進行迭代。但是當我調試時,var(resultviews)的數據記憶包含執行foreach之前的結果值。爲什麼發生這種情況?