Initially, I 'dict' and 'dict2' which is a copy of 'dict'. If I replace a Key in 'dict', the change is applied to dict2 too. How can this be avoided? Below is some sample code.
Sub Main()
Dim dict As New Dictionary(Of String, Object) From {{"Big", "Small"}, {"Hot", "Cold"}}
Dim dict2 As New Dictionary(Of String, Object) : dict2 = dict
If dict.ContainsKey("Hot") Then 'Only makes changes to dict
dict.Add("Warm", dict("Hot").ToString)
dict.Remove("Hot")
End If
writeDict(dict) 'Displays said changes
writeDict(dict2) 'Displays same changes as dict
End Sub
Sub writeDict(dict As Dictionary(Of String, Object)) 'Ignore this
For Each i As KeyValuePair(Of String, Object) In dict
Console.Write(i.ToString)
Next
Console.ReadLine()
End Sub
Ideally I would pass in 'dict' to another Sub, validate it by replacing some keys, then exit the Sub. Then I would resume working with the original dictionary.
But currently that's not working, because changes to dictionaries seem to be global.