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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top