PC Review


Reply
Thread Tools Rate Thread

Collection enumeration exception

 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      15th Mar 2005
Chuck,

Are you removing the item while you are enumerating through it? If so,
then this is not allowed. You need to cycle through the object using the
indexer, or whatever other access method there is to get an item from the
object.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Chuck Bowling" <(E-Mail Removed)> wrote in message
news:%23PDtL$(E-Mail Removed)...
>I have a collection that I want to edit. When I remove an object from the
>collection and then try to enumerate thru it with the foreach statement it
>throws an exception - "Collection was modified; enumeration operation may
>not execute."
>
> Can somebody tell me how to fix this?
>
>



 
Reply With Quote
 
 
 
 
Chuck Bowling
Guest
Posts: n/a
 
      15th Mar 2005
I have a collection that I want to edit. When I remove an object from the
collection and then try to enumerate thru it with the foreach statement it
throws an exception - "Collection was modified; enumeration operation may
not execute."

Can somebody tell me how to fix this?


 
Reply With Quote
 
Chuck Bowling
Guest
Posts: n/a
 
      16th Mar 2005
Thanks Nicholas. I feel like an idiot. Forgot the thing was in a big loop...
Whoops...

"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Chuck,
>
> Are you removing the item while you are enumerating through it? If so,
> then this is not allowed. You need to cycle through the object using the
> indexer, or whatever other access method there is to get an item from the
> object.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Chuck Bowling" <(E-Mail Removed)> wrote in message
> news:%23PDtL$(E-Mail Removed)...
>>I have a collection that I want to edit. When I remove an object from the
>>collection and then try to enumerate thru it with the foreach statement it
>>throws an exception - "Collection was modified; enumeration operation may
>>not execute."
>>
>> Can somebody tell me how to fix this?
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting numeric enumeration value does not throw exception Steve Wilkinson Microsoft Dot NET Framework 3 19th May 2008 12:59 PM
Need exception enumeration =?Utf-8?B?cG9seW5vbWlhbDVkQHlhaG9vLmNvbQ==?= Microsoft ADO .NET 2 22nd Mar 2004 09:02 AM
Collection was modified; enumeration operation may not execute . Exception ? Anders Both Microsoft C# .NET 3 20th Jan 2004 08:03 AM
Thread-safe enumeration thru collection? Grandma Wilkerson Microsoft Dot NET 1 23rd Sep 2003 11:02 PM
Thread-safe enumeration thru collection? Grandma Wilkerson Microsoft C# .NET 3 15th Aug 2003 04:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 PM.