I'm a hardware engineer doing my first c# program.
I have 2 global lists defined in my form as:
List MemoryBank = new List(100);
List CombinedMemories = new List(100);
The first list is used by several functions. Sooner or later, I must do "garbage collection" in a different function and extract (copy) the useful elements of the first list into the second list. This works the first time, but when I do that, the references are then set to be the same. The next time I update an element in the first list, the paired entry in the second list is also updated. I don't want that.
I tried to prevent this by reading the element of the first list into a temporary (local) variable and then copying the temp into the second list, but apparently when the local variable is destroyed the elements still have the same reference.
What's the right way to fix this?
0 · ·