Are there any C# collections where modification does not invalidate iterators?
Posted
by young-phillip
on Stack Overflow
See other posts from Stack Overflow
or by young-phillip
Published on 2010-05-02T14:16:12Z
Indexed on
2010/05/02
14:27 UTC
Read the original article
Hit count: 205
Are there any data structures in the C# Collections library where modification of the structure does not invalidate iterators?
Consider the following:
List<int> myList = new List<int>();
myList.Add( 1 );
myList.Add( 2 );
List<int>.Enumerator myIter = myList.GetEnumerator();
myIter.MoveNext(); // myIter.Current == 1
myList.Add( 3 );
myIter.MoveNext(); // throws InvalidOperationException
© Stack Overflow or respective owner