For the life of me, I can't figure out why all the foos are not null.
I'm assuming the .ForAll()
should be executing before I call the .All()
method, but it's not?
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 ??
}
Bar
property to another value, that value doesn't stick either. I'm still a bit perplexed; I'm under the assumption thatForAll()
is iterating over the actual list. In other words, why would the lambda not beref
? – Bronchiectasis