How to merge dictionaries in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
    Public Shared Sub Main()
		Dim dict1 = New Dictionary(Of string, object)() From {
			{"vb", ".net"},
            {"version", 16.9},
            {"java", 19}
        }

		Dim dict2 = New Dictionary(Of string, object)() From {
			{"computer", 1700},
			{"3d", "programming"},
			{"math", 3.14}
        }
        
		Dim mergedict = New Dictionary(Of String, Object)()

        For Each entry In dict1.Concat(dict2)
            mergedict(entry.Key) = entry.Value
        Next

        For Each element In mergedict
            Console.WriteLine(element)
        Next
    End Sub
End Class





' run
'
' [vb, .net]
' [version, 16.9]
' [java, 19]
' [computer, 1700]
' [3d, programming]
' [math, 3.14]
'

 



answered Dec 12, 2022 by avibootz
...