ahhh yeah ok....got it. problem is fixed now.
how would i copy the contents of one variable into another
one and not
have it just be a reference to the first variable but
independant from
it?
thanks for the help
ian
On 5/26/06, Joseph Bradvica <jbradvica sta-usa.com> wrote:
> The second variable is a 'reference' to the first.
So you are really
> removing an item to the original.
>
> Joe B.
>
> -----Original Message-----
> From: merk imerk.com [mailto:merk imerk.com] On Behalf Of Ian Lipsky
> Sent: Friday, May 26, 2006 3:19 PM
> To: aspnet aspadvice.com
> Subject: [aspnet] RE: Collection was modified
>
>
> yeah i kinda realized that was probably was happening
about 2 minutes
> after i sent the email ;)
>
> however, i tried fixing it by using a 2nd variable to
store collection:
>
> ISet tmpcampaigns = campaigns;
> foreach (Campaign c in
campaigns)
> {
> if (c.Disabled == true)
> {
>
tmpcampaigns.Remove(c);
> }
> }
>
> but it still gives me the same error. I dont understan
why it would
> error now.
>
> thanks
>
> Ian
>
> On 5/26/06, Steven A Smith <steven.smith aspalliance.com> wrote:
> > The collection indexer can get confused if you
modify the collection
> in the
> > middle of a foreach. The preferred way to do what
you're doing is to
> get
> > the Keys and loop through them, rather than
foreach-ing through the
> > collection directly.
> >
> > Steve
> >
> > -----Original Message-----
> > From: merk imerk.com [mailto:merk imerk.com] On Behalf Of Ian Lipsky
> > Sent: Friday, May 26, 2006 6:05 PM
> > To: aspnet aspadvice.com
> > Subject: [aspnet] Collection was modified
> >
> > can someone please tell me why this error is
occuring?
> >
> >
> > private ISet packages = new HybridSet(); private
ISet campaigns = new
> > HybridSet();
> >
> > private void Page_Load(object sender,
System.EventArgs e)
> > {
> > packages = user.Packages;
> > campaigns = user.Campaigns;
> > BindControls();
> > }
> >
> >
> > private void BindControls()
> > {
> >
> > foreach (Package p in packages)
> > {
> >
campaigns.RemoveAll(p.Campaigns);
> > }
> >
> >
> > ==> foreach (Campaign c in campaigns)
> > {
> > if (c.Disabled == true)
> > {
> >
campaigns.Remove(c);
> > }
> > }
> > }
> >
> > it fails on the 2nd foreach loop right on the
foreach line i marked.
> > I've tried wrapping the statements in lock()
which i found suggested
> on one
> > site but it makes no difference. The first foreach
loop works fine.
> >
> > ian
> >
> >
> > Need SQL Advice? http://sqladvice.com
> > Need RegEx Advice? http://regexadvice.com
Need XML Advice?
> > http://xmladvice.com
> >
> >
> >
> > Need SQL Advice? http://sqladvice.com
> > Need RegEx Advice? http://regexadvice.com
> > Need XML Advice? http://xmladvice.com
> >
> >
>
>
> Need SQL Advice? http://sqladvice.com
> Need RegEx Advice? http://regexadvice.com
> Need XML Advice? http://xmladvice.com
>
> Need SQL Advice? http://sqladvice.com
> Need RegEx Advice? http://regexadvice.com
> Need XML Advice? http://xmladvice.com
>
>
Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com
|