[Mono-list] IEnumerators

David Menestrina dmenest@yahoo.com
Tue, 17 Jul 2001 00:52:11 -0700 (PDT)


IEnumerator.MoveNext() has to throw
InvalidOperationException if the object it's 
enumerating is modified in any way.  I tested this
with MS's implementation of BitArray, and it seems to
really detect *any* change to the original object.

Maybe my brain is fried, but I can't seem to think
of a great way to implement this.  The best way I can
think of is to have the original object keep a change
count.  Whenever any call modifies the object,
increment the count.  The IEnumerator will store
the value on creation, then check it every time you
call MoveNext().

This works in all cases except when you modify
something 4 billion times before calling MoveNext.

Does anyone have a cleaner idea?  I can't keep
pointers
to all the IEnumerators, because then they'd never
get GC'ed.

Thanks,
david

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/