C
C#4mo ago
Ace Guy

✅ 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
No description
13 Replies
Ace Guy
Ace Guy4mo ago
if i remove differenceList.add(obj); then it doesn't crash
Angius
Angius4mo ago
What's differenceList?
Ace Guy
Ace Guy4mo ago
a string HashSet
Angius
Angius4mo ago
Are you looping over it as well?
Ace Guy
Ace Guy4mo ago
I don't think so
Angius
Angius4mo ago
The error would happen only if you modify input inside of the loop So I wonder if, perhaps, differenceList holds a reference to input
Ace Guy
Ace Guy4mo ago
well there is differenceList = input; before the cycle starts, that could be the problem brb
Angius
Angius4mo ago
Yes, that means differenceList and input are one and the same differenceList is just an alias for input
Ace Guy
Ace Guy4mo ago
ooooooooh
Angius
Angius4mo ago
So by modifying the former, you modify the latter
Ace Guy
Ace Guy4mo ago
how can I make the contents the same but not link them like that?
Angius
Angius4mo ago
If it's a hashset, try .ToHashSet()
differenceList = input.ToHashSet();
differenceList = input.ToHashSet();
Ace Guy
Ace Guy4mo ago
oh yeah that seems to have worked, tysm!
Want results from more Discord servers?
Add your server
More Posts
Class Naming ConventionsI'm currently renaming all the classes in my Discord Bot project but I'm stumped to decide what the ✅ [AVALONIA] Get all coordinates along a PolylineWhilst you define the points for a Polyline, is there any way that I can get or calculate the rest oCleaner NavigationView implementation (Avalonia)I'm currently porting an existing project that i didn't write from WinUI3 to Avalonia. The project Iprogram closing early```cs Console.WriteLine("What was the digital portfolio mark (out of 35)?"); int dpMark = int.Parse(Fully stuck on making a clickable game object system in unityim fully stuck right now, I cant find a good solution for this problem, so basically im making a gam✅ [AVALONIA] Return Coordinates (Only if a Polyline is present in those coordinates)Ive completed my A* Pathfinding but need to dump alot of uneccesary coordinates from the created grineed some help understanding configuration comming from "Environment Variables"so I read some docs that says I should store secrts for development using the Secrets.json service. ✅ Return Coordinates (Only if a Polyline is present in those coordinates)Ive completed my A* Pathfinding but need to dump alot of uneccesary coordinates from the created griI need help debugging c# event-based reliable UDP implementation.Note: I know that there are libraries that can do this and even more. But for my own reasons, I wantHow to register with email AND username?I am using this tuto: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity