How to compare two dictionaries?

Hi All

I have two dictionaries. Both contain Name and Value pairs. I have to compare both the dictionaries whether they contain same pairs or different pairs.

Can anyone help how do we compare dictionaries ?

1 Like

Hello @kkpatel,

Dict1Var(“Key”).ToString = Dict2(“YourKey”).ToString
Cheers

Thanks @Pradeep_Shiv.

Also can you please help if we have two data tables. Its like comparing rows. If rows of both data tables are same and which are the rows different.

1 Like

row.item(0) = row.item(1)

@kkpatel

1 Like

So you are comparing col1 data with col2 data in the same data table ?

1 Like

@kkpatel

Comparing Dictionaries can be quick done with the help of DataSet Operations
Lets assume following:
grafik

dict1 and dic2 are common on B20,
kindly note: C"30" differs to C30 as first one is 30 as String, second one is 30 as Integer

finding the common entries can done with the Intersect:

dict1.Intersect(dict2).ToDictionary(Of String, Object)(Function (k) k.Key, Function (v) v.Value)

finding the not common entries related to the common entries in the dict can be done with an Except:

e.g. For dict1

dict1.Except(dictCommon).ToDictionary(Of String, Object)(Function (k) k.Key, Function (v) v.Value)

Find starter Help here:
Find_MatchingNonMatchingEntries_2Dicts.xaml (6.4 KB)

For DataTables the Join DataTable Activity is helping
find starter help here:
Get_MatchingNonMatching_JoinActivity.xaml (13.7 KB)

Fur more custom cases LINQ can often help to adress specifics

Let us know your feedback

2 Likes