Create a “clone” of this object, not point to it

2019-01-26 09:48发布

Let's say I got a list called

myFirstList

And then I want to create a copy of that list so I can do some tweaks of my own. So I do this:

mySecondList = myFirstList
mySecondList.doTweaks

But I noticed that the tweaks also affect the myFirstList object! I only want the tweaks to affect the second one...

And afterwards I will want to completely delete mySecondList, so I do mySecondList = Nothing and I'm good, right?

7条回答
够拽才男人
2楼-- · 2019-01-26 10:33

Since you have not divulged the type of item that you are storing n your list, I assume it's something that's implementing IClonable (Otherwise, if you can, implement IClonable, or figure out a way to clone individual item in the list).

Try something like this

mySeconmySecondList = myFirstList.[Select](Function(i) i.Clone()).ToList()
查看更多
登录 后发表回答