У меня есть два словарных объекта один из двух типов Dictionary(of Integer, string)
.сравнить два словарных значения ключа
Мне нужно проверить, повторяется ли значение ключа в первом словаре i.e. dc1 в словаре dc2, если так получить ключ от повторяющегося значения ключа. ниже код работает, но есть гораздо лучший способ сделать сравнение
Dim dc1 As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
Dim dc2 As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
dc1.Add(1, "student1")
dc1.Add(2, "student2")
dc1.Add(3, "student3")
dc1.Add(4, "student4")
dc2.Add(1, "student1")
dc2.Add(2, "student4")
dc2.Add(3, "student2")
dc2.Add(4, "student3")
dc2.Add(10, "student1")
dc2.Add(11, "student4")
Dim lstcount1 As List(Of Integer) = New List(Of Integer)
For Each kvp1 As KeyValuePair(Of Integer, String) In dc1
Dim count As Integer = 0
For Each kvp2 As KeyValuePair(Of Integer, String) In dc2
If kvp1.Value = kvp2.Value Then
count = count + 1
If (count > 1) Then
lstcount1.Add(kvp2.Key)
End If
End If
Next
Next