Matching values from two dictionaries

I have two dictionaries ,

Dict1 will have few set of values like
Account number - 1234
Name- xxx
Date - 20/12/2023

Dict2 will have few set of values
Account number - 1234
Name -yyyy
Date -23/22/2023

Now my condition is ,
I’ll have to compare the values in both dict and find if it’s same .

Value of acct number in dict 1 = value of acct number in dict 2 . If it’s same I should proceed with this or I should move to next condition .

If in small keys we can compare with their key name , but in bulk values, checking each and every key will be difficult right ?

Is there a way to find if the values matches in two configs ?

@Ragavi_Rajasekar

You can loop through the keys and then use compare inside

For loop with dict1.keys

Inside it use if condition with dict1(currentitem).ToString.Equals(dict2(currentItem).ToString)

On then side do nothing…else side you can keep a flag and exit the loop usingg exit…

That way after loop we can check the bool_value

Initializing it with false and then on else side set to true and outside loop check with if condition if bool_value is true or false

Cheers

You could give this a try:

myDictionary = (From entry In Dict1
                Where Dict2.ContainsKey(entry.Key) AndAlso Dict2(entry.Key).ToString = entry.Value.ToString
                Select entry).Count = Dict1.Count AndAlso Dict1.Count = Dict2.Count

Hello @Ragavi_Rajasekar

  1. Assign

    dict1 = New Dictionary(Of String, Object) From
    {“Account number”, “1234”},
    {“Name”, “xxx”},
    {“Date”, “20/12/2023”}

    dict2 = New Dictionary(Of String, Object) From
    {“Account number”, “1234”},
    {“Name”, “yyy”},
    {“Date”, “23/12/2023”}

    allValuesMatch = dict1.Values.All(Function(val) dict2.Values.Contains(val))

  2. If
    Condition: allValuesMatch
    Then: (Values in dict1 and dict2 are the same)
    Else: (Values in dict1 and dict2 are not the same)

Thanks & Cheers!!!

@Ragavi_Rajasekar

Try this Linq

(From kvp1 In Dict1
Join kvp2 In Dict2 On kvp1.Key Equals kvp2.Key
Where kvp1.Value.ToString() = kvp2.Value.ToString()
Select kvp1.Key).ToList()

Cheers…!