按照此链接: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之前的结果值。为什么发生这种情况?