Scott Watermasysk [mailto:[EMAIL PROTECTED]] wrote:

> Is it possible to enumerate a collection while still adding
> new items to it? One of my applications needs to populate a
> collection, then I need to walk through this collection
> possibly adding new items to the collection until no new
> items are found. (I am certain this will not enter an
> infinite loop). Is this possible? Is there a better way to
> approach this?

>From the SDK docs on IEnumerator[1]:

<snip>
An enumerator remains valid as long as the collection remains unchanged. If
changes are made to the collection, such as adding, modifying or deleting
elements, the enumerator is irrecoverably invalidated and the next call to
MoveNext or Reset throws an InvalidOperationException. If the collection is
modified between MoveNext and Current, Current will return the element that
it is set to, even if the enumerator is already invalidated.
</snip>

HTH,
Drew
.NET MVP

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemCollectionsIEnumeratorClassTopic.asp OR
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemCollectionsIEnumeratorClas
sTopic.htm

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to