CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #5
    Join Date
    Mar 2007
    Posts
    155

    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.

    Quote Originally Posted by Arjay View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured