modify list value with foreach iteration variable

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi,
I have a list of widgets.
I want to iterate through the selected items collection and modify one of
the widgets properties.
I tried
foreach(widget w in lst.SelectedItems)
w.MyProperty = something;
but I get a message saying "Cannot modify members of w because it is a
foreach iteration variable"
What is the point of iteration if you can't modify the objects?
Thanks
Bob
 
Bob said:
foreach(widget w in lst.SelectedItems)
w.MyProperty = something;
but I get a message saying "Cannot modify members of w because it is a
foreach iteration variable"

What is widget? What is lst? What is MyProperty?
What is the point of iteration if you can't modify the objects?

You can modify the objects. You can't modify the collection, though. If
modifying the object would cause it to modify the collection, then that
isn't allowed.

I think your complaint would be more meaningful if it was precise!

-- Barry
 
Hi Barry,
Thanks for your reply.
Problem solved. My mistake was assuming that a listbox items collection
could have it members modified.
regards
Bob
 
Back
Top