Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Shallow Copy Problems

Started by RobotechII Dec 21, 2005 at 2:47 AM 1 replies 550+ views
Original Post
RobotechII
RobotechII
I'm fairly new to C# and I'm having some problems trying to get a List<> to deep copy. SGenome elite = new SGenome(); elite.lstBits = lstBestGenome; Later on when I lstBestGenome.Clear() my elite.lstBits is gone. Any help would be appreciated.
SiCrane
SiCrane
You're only copying List<> references not List<>s. Another approach is use new to create a new List<> and use the IEnumerable version of the List<> constructor to copy the data from the other list.
RobotechII
RobotechII
Quote:
Original post by SiCrane
You're only copying List<> references not List<>s. Another approach is use new to create a new List<> and use the IEnumerable version of the List<> constructor to copy the data from the other list.


Thank you that fixed it. I meant to see if List<> was overloaded last night but in my frustration never got around to it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.