Here we create a Dictionary, then copy it—and then when the original is modified, the copy remained unchanged. This shows that the 2 Dictionaries are entirely separate.
Module Module1
Sub Main(args as String())
' Step 1: create a Dictionary.
Dim dictionary = New Dictionary(Of String, Integer)()
dictionary.Add(
"cat", 1)
dictionary.Add(
"dog", 3)
dictionary.Add(
"iguana", 5)
' Step 2: copy the Dictionary to a second Dictionary.
Dim copy = New Dictionary(Of String, Integer)(dictionary)
' Step 3: modify the original Dictionary.
dictionary.Add(
"fish", 4)
' Step 4: display the 2 separate Dictionaries.
For Each pair in dictionary
Console.WriteLine($
"ORIGINAL: {pair}")
Next
For Each pair in copy
Console.WriteLine($
"COPY: {pair}")
Next
End Sub
End Module
ORIGINAL: [cat, 1]
ORIGINAL: [dog, 3]
ORIGINAL: [iguana, 5]
ORIGINAL: [fish, 4]
COPY: [cat, 1]
COPY: [dog, 3]
COPY: [iguana, 5]