✅ Can't modify a list outside of the cycle
So I'm trying to modify differenceList in a cycle, but it gives me an error (see attachment), although differenceList isn't a part of the cycle and shouldn't be a problem
//please ignore my poor variable naming
13 Replies
if i remove
differenceList.add(obj);
then it doesn't crashWhat's
differenceList
?a string HashSet
Are you looping over it as well?
I don't think so
The error would happen only if you modify
input
inside of the loop
So I wonder if, perhaps, differenceList
holds a reference to input
well there is
differenceList = input;
before the cycle starts, that could be the problem
brbYes, that means
differenceList
and input
are one and the same
differenceList
is just an alias for input
ooooooooh
So by modifying the former, you modify the latter
how can I make the contents the same but not link them like that?
If it's a hashset, try
.ToHashSet()
oh yeah that seems to have worked, tysm!