Re: foreach loop error

Discussion in 'ASP .Net' started by Luc Kumps, Aug 22, 2003.

  1. Luc Kumps

    Luc Kumps Guest

    "Will" <> wrote in message
    news:061401c368f1$e58c9ab0$...
    > I'm trying to run through all of the listitems in a
    > listbox with a foreach loop. it looks like this:
    >
    >
    > foreach (ListItem temp in mymListBox.Items) {
    > if ((temp.ToString()).StartsWith(string)) {
    > chosenPractices.Items.Remove(temp);
    > }
    > }
    >
    > I get the following error on the very first line:
    >
    > System.InvalidOperationException: Collection was modified;
    > enumeration operation may not execute.


    Besides working from the back to the front, have a look at the IterIsolate
    marvel...

    http://msdn.microsoft.com/library/en-us/dncscol/html/csharp01212002.asp

    Luc K
    Luc Kumps, Aug 22, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: foreach loop error

    Kevin Spencer, Aug 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    351
    Kevin Spencer
    Aug 22, 2003
  2. =?Utf-8?B?SnVzdGlu?=

    Problem with foreach loop

    =?Utf-8?B?SnVzdGlu?=, Oct 22, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    317
    Hans Kesting
    Oct 22, 2004
  3. Islam Elkhayat

    loop througth Literials using foreach!!

    Islam Elkhayat, Feb 10, 2005, in forum: ASP .Net
    Replies:
    16
    Views:
    732
    Scott Allen
    Feb 12, 2005
  4. ad
    Replies:
    2
    Views:
    14,601
    Peter Rilling
    Jun 6, 2005
  5. Isaac Won
    Replies:
    9
    Views:
    352
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page