Is there an easier/tidier way to deep clone a list of reference types that do not implement ICloneable.
Currently have been looping through each object in the list like so:
Dim myListCopy As New List(Of ListObj)
For Each lo As ListObj In MyList
myListCopy.Add(lo.ShallowCopy)
Next
The object ListObj contains only value types and returns a shallow memberwise.
This works however I cam across this post here: How do I clone a generic list in C#?
I don’t really understand whats going on in the Extension, is it possible to the shollowCopy function to an extension and avoid iteration?
If you write an extension method, it will still have to iterate over your list in some way or other. For VB.net, the extension method will look something like…
Then when you need to shallow copy your list of ListObj items, you would…