Dim i = 2
Do While True
i += 1
If IsDBNull(TmDataSet.T.Rows(0)(i)) = True Then Exit Do
Dim new_t As New train
new_t.id = TmDataS
You can create an extension method where you serialize the object only to deserialize it again. This will create a new object with it's own references, thus a Deep Copy.
Public Module Extensions
<System.Runtime.CompilerServices.Extension()> _
Public Function DeepCopy(Of T)(ByVal Obj As T) As T
If Obj.GetType().IsSerializable = False Then Return Nothing
Using MStream As New MemoryStream
Dim Formatter As New BinaryFormatter
Formatter.Serialize(MStream, Obj)
MStream.Position = 0
Return DirectCast(Formatter.Deserialize(MStream), T)
End Using
End Function
End Module
Now you can just call:
Dim network As List(Of train) = per_network.DeepCopy()
EDIT:
These are the required imports for my code above:
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
This is the code I used
Dim deepCopies = _dictOfBalances1.Keys.ToList
Basically deepCopies is a deep copy of _dictOfBalances1.Keys
This code won't work if deepCopies are shallow copies.
For Each code In deepCopies
If allthecoincode.Contains(code) Then
Else
_dictOfBalances1.Remove(code)
'deletedKeys.Add(code)
End If
Next