I was just curious about this: the following code will not compile, because we cannot modify a foreach iteration variable:
foreach (var item in MyObjectList)
{
item = Value;
}
But the following will compile and run:
foreach (var item in MyObjectList)
{
item.Value = Value;
}
Why is the first invalid, whereas the second can do the same underneath (I was searching for the correct english expression for this, but I don't remember it. Under the...? ^^ )
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…