Imports System
Imports System.Collections.Generic
Class Program
Public Shared Sub Main()
Dim dict1 = New Dictionary(Of Integer, String) From {
{1, "aaa"},
{2, "bbb"}
}
Dim dict2 = New Dictionary(Of Integer, String) From {
{3, "ccc"},
{4, "ddd"},
{2, "XYZ"}
}
Dim combined = New Dictionary(Of Integer, String)(dict1)
For Each kvp In dict2
If combined.ContainsKey(kvp.Key) Then
combined(kvp.Key) += ", " & kvp.Value
Else
combined(kvp.Key) = kvp.Value
End If
Next
For Each kvp In combined
Console.WriteLine($"{kvp.Key}: {kvp.Value}")
Next
End Sub
End Class
' run:
'
' 1: aaa
' 2: bbb, XYZ
' 3: ccc
' 4: ddd
'