【发布时间】:2015-05-26 23:57:53
【问题描述】:
对于我的生活,我无法弄清楚为什么所有的 foos 都不为空。
我假设在调用.All() 方法之前应该执行.ForAll(),但不是吗?
public class Foo
{
public string Bar { get; set; }
}
static void Main(string[] args)
{
var foos = new List<Foo> { new Foo(), new Foo(), new Foo() };
var newFoos = foos
.AsParallel()
.Select(x =>
{
x.Bar = "";
return x;
});
newFoos.ForAll(x => x = null);
var allFoosAreNull = newFoos.All(x => x == null);
Console.WriteLine(allFoosAreNull); // False ??
}
【问题讨论】: