When items change while being enumerated does it affects the enumeration?
问题 Imagine that during a foreach(var item in enumerable) The enumerable items change. It will affect the current foreach? Example: var enumerable = new List<int>(); enumerable.Add(1); Parallel.ForEach<int>(enumerable, item => { enumerable.Add(item + 1); }); It will loop forever? 回答1: Generally, it should throw an exception. The List<T> implementation of GetEnumerator() Provides an Enumerator<T> object whose MoveNext() method looks like this (from Reflector): public bool MoveNext() { List<T> list