0

I'm trying to copy a list to a list, but it keeps copying it by reference, so a change in one changes the other. I tried cloning but it didn't copy the parent- child relationship.

foreach (TreeNode item in listNodesdestination) 
      testNode1.Add((TreeNode)item.Clone());

thanks.

wtjones
  • 4,090
  • 4
  • 34
  • 41
Shnerka Zoid
  • 107
  • 1
  • 1
  • 6

1 Answers1

0

Since it is serializable, you could perform a deep copy using a memory stream. deep copy via memory stream - stack overflow

Community
  • 1
  • 1
wtjones
  • 4,090
  • 4
  • 34
  • 41