在延迟求值的情况下,只是定义了一个查询,而且不是立刻执行。
List<int> list = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var temp1 = from c in list where c > 5 select c; var temp2 = (from c in list where c > 5 select c).ToList<int>(); Console.WriteLine(temp1.GetType()); Console.WriteLine(temp2.GetType()); list[0] = 11; Console.WriteLine("temp1: "); foreach (var item in temp1) { Console.WriteLine(item.ToString() + " "); } Console.WriteLine("\n temp2: "); foreach (var item in temp2) { Console.WriteLine(item.ToString() + " "); } Console.WriteLine("Hello World!");
标签:Console,LINQ,var,temp2,temp1,WriteLine,求值,延迟 From: https://www.cnblogs.com/wen-chen/p/16991746.html