从LINQ 测验问题和答案到 Q4 和 Q5
数组colors定义为:
string[] colors = { "green", "brown", "blue", "red" };
并从对 Q4 的回答中查询:
var query =
from c in colors
where c.Length == colors.Max (c2 => c2.Length)
select c;
我是否正确理解外部查询迭代表达式c2.Length将被评估 16 次?
也就是说,对于数组中的每个项目,с将计算一次,即计算将总共进行 4 次。并且对于每次评估会发现 4 次? colorscolors.Max (c2 => c2.Length)Max()Max()c2.Length