Alternative loop

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hello,

I'm doing the following.

IDictionaryEnumerator iter = Persons.GetEnumerator();

while ( iter.MoveNext() ) {
Person person = ( Persons ) iter.Value;
if ( person.SameAge( Age ) ) {
Persons.Remove( person.GetHashCode() );
}
}

Now I get an error.
The error says that I have changed the Persons collection.
This is correct. Because I removed a person.

How can I walk through all Persons?
With not using while ( iter.MoveNext() ).
Can you give me an example?

Thanks!
 
Back
Top