this time I’ve got an C# programming issue:
I’ve got a list of lists:
List<List<string>> List1
And that list of strings in it:
List<string> List2
And, in loop, I want to put List2 in List1, but then, I want to change values in List2, but I don’t want to change this values in the List2 which was inserted in List1.
Here is the example with pseudo-code of what I want to do (because I suppose nobody gets what I want at the moment):
List1 <=> ['one', 'two', 'three']
List2[1] <=> List1
List1.clear
List1 <=> ['four', 'five', 'six']
List2[2] <=> List1
but List1 changed in List2[1] too – I don’t want that! It looks like now:
List2[1] <=> ['four', 'five', 'six']
List2[2] <=> ['four', 'five', 'six']
But I want that it will be:
List2[1] <=> ['one', 'two', 'three']
List2[2] <=> ['four', 'five', 'six']
What’s the point? I want that these List1s stay in that state, what there were when I was inserting them to the List2. I hope someone will understand this and will help me.
I know that I’m inserting some kind of List1 pointners in List2, but how make it right? (right -> the way I want it to work^^)
You want to put a copy of
List1inList2:Otherwise,
List1,List2[1]andList2[2]reference the same list, so by changing one, you’re also changing the others.