I developed a small function when trying to start an enumerator on a list and then perform some action. (Below is the idea of what I was trying to do.
When I tried to delete, I got "Collection cannot be changed", which, after I really woke up, realized that tempList should just be assigned as a link to myLists, and not a copy of myLists. After that I tried to find a way to say
tempList = myList.copy
However, nothing similar exists ?? I ended up writing a little loop, which then added only every element from myLsit to tempList, but I would have thought there would be another mechanism (e.g. clone?)
So my question (s):
- - my assumption is that tempList gets the link to myList correctly.
How should a list be copied to another list?
private myList as List (Of something)
sub new()
myList.add(new Something)
end sub
sub myCalledFunction()
dim tempList as new List (Of Something)
tempList = myList
Using i as IEnumerator = myList.getEnumarator
while i.moveNext
'if some critria is met then
tempList.remove(i.current)
end
end using
end sub
source
share