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 = this.list;
if ((this.version == list._version) && (this.index < list._size))
{
this.current = list._items[this.index];
this.index++;
return true;
}
return this.MoveNextRare();
}
private bool MoveNextRare()
{
if (this.version != this.list._version)
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
}
this.index = this.list._size + 1;
this.current = default(T);
return false;
}
The list._version
is modified (incremented) on each operation which modifies the List.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…