How can I get an item from a list as a new copy/instance, so I can use and change it later without changing the original object in the list?
Public Class entry
Public val As String
' ... other fields ...
End Class
Dim MyList As New List(Of entry)
Dim newitem As New entry
newitem.val = "first"
MyList.Add(newitem)
Now if I try to get an item from this list and change it to something else, it changes the original item in the list as well (it is used as a reference not as a new instance).
Dim newitem2 As New entry
newitem2 = MyList.Item(0)
newitem2.val = "something else"
So now the MyList.item(0).val
contains "something else", yet I wanted only the newitem2
to contain that new value for the given field and retain other values from the object in the list.
Is there a way to do this without reassigning all fields one by one?