Actually, I found a better (native?) way of doing it which
makes more sense I guess.
This method is to do the for-each on a NEW instance of the
NameValueCollection passing the existing
NameValueCollection in the New Constructor. Then removing
the items from the original collection. It works great for
me.
Example:
dim a as new NameValueCollection
a.add("name-a","value-a")
a.add("name-b","value-b")
a.add("name-c","value-c")
dim item as string
for each item in New NameValueCollection(a)
if a(item) = "value-b" then
a.remove(item)
end if
next
this will result in value-b being removed, but not
interrupting the for-each loop
-Walt
-----Original Message-----
You could iterate starting at the end using a
standard "for" loopdecrementing the index for each item. When you come
across an item that youdo not want, you can remove it and continue. The reason
for starting at theend is because as you remove the item, the length of the
collection changesso your loop's ending condition is no longer valid.
However, the index forthe first element never changes.
"Walter Zydhek" <wa**@giftmarket.org> wrote in message
news:03****************************@phx.gbl... I am having a problem using the NameValueCollection
type.
If I remove one of the items while iterating through an
collection of this type, I end up with an exception.
This exception is:
Collection was modified after the enumerator was
instantiated.
This happens when it attempts to continue through the
enumeration.
Is there a way around this? Is there another way to
remove items from the collection while iterating through
it?
-Walter Zydhek
.