-
December 9th, 2012, 05:25 AM
#1
Iterating a collection that constantly changes
I want iterate a collection, but before I finish to iterate, the collection is modified.
So, whenever the collection is modified, I want to re-iterate the collection from the beginning again.
Any inputs on how will I achieve this?
-
December 9th, 2012, 05:31 PM
#2
Re: Iterating a collection that constantly changes
What kind of collection, specifically? List? Dictionary?
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
December 10th, 2012, 02:25 AM
#3
Re: Iterating a collection that constantly changes
It's a collection from a library. It implemented CollectionBase, which in-turn implemented IList, ICollection, IEnumerable. I've no control over the library as to when the collection will be modified.
-
December 10th, 2012, 01:53 PM
#4
Re: Iterating a collection that constantly changes
Can you clarify how you propose to handle notifications when the collection changes in the middle of your iteration? Are you sending an event that indicatates a change? Does the enumerator return a copy of the collection (or does it return a reference to the actual underlying collection)?
-
December 11th, 2012, 12:51 AM
#5
Re: Iterating a collection that constantly changes
Thank you BioPhyEngr and Arjay.
Let's say the original collection has a, b, c.
a, b, c - auto created
I want to manually create same number of elements as in the collection
d, e, f - manually created
After that, I want to add it to the original collection. In the end, it will be-
a, b, c, d, e, f
The framework will notify me whenver a, b, c is changed. The d, e, f I created is dependent on values of a, b, c. The problem I face is in creation of d, e, f. To create d, e, f I want to iterate the original collection, but while I was iterating, the collection was modified.
In short I want to make sure the original collection will always have same number of manually created elements.
Originally Posted by Arjay
Can you clarify how you propose to handle notifications when the collection changes in the middle of your iteration? Are you sending an event that indicatates a change? Does the enumerator return a copy of the collection (or does it return a reference to the actual underlying collection)?
I'll not send any notification. I just want to make sure the collection have same number of my custom created elements.
Does the enumerator return a copy of the collection (or does it return a reference to the actual underlying collection)?
It's sending the actual underlying collection. But I can use .ToArray() if I need a copy.
Last edited by thomus07; December 11th, 2012 at 12:56 AM.
Reason: Added my answers to Arjay's question
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|