{"id":2648,"date":"2025-06-12T12:51:29","date_gmt":"2025-06-12T04:51:29","guid":{"rendered":"https:\/\/www.clonefactor.com\/wordpress\/?p=2648"},"modified":"2025-06-12T13:05:02","modified_gmt":"2025-06-12T05:05:02","slug":"detect-changed-items-between-2-dictionary","status":"publish","type":"post","link":"https:\/\/www.clonefactor.com\/wordpress\/program\/c\/2648\/","title":{"rendered":"detect changed items between 2 dictionary"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static void DiffDictionaries&lt;T, U&gt;(\n    Dictionary&lt;T, U&gt; dicA,\n    Dictionary&lt;T, U&gt; dicB,\n    out Dictionary&lt;T, U&gt; dicAdd,\n    out Dictionary&lt;T, U&gt; dicDel)\n{\n    \/\/ dicDel has entries that are in A, but not in B, \n    \/\/ ie they were deleted when moving from A to B\n    int diff = Mathf.Abs(dicA.Count - dicB.Count);\n    dicDel = new Dictionary&lt;T, U&gt;(diff);\n    diffDicSub(dicA, dicB, dicDel);\n\n    \/\/ dicAdd has entries that are in B, but not in A,\n    \/\/ ie they were added when moving from A to B\n    dicAdd = new Dictionary&lt;T, U&gt;(diff);\n    diffDicSub(dicB, dicA, dicAdd);\n\n    void diffDicSub(\n    Dictionary&lt;T, U&gt; dicA,\n    Dictionary&lt;T, U&gt; dicB,\n    Dictionary&lt;T, U&gt; dicAExceptB)\n    {\n        \/\/ Walk A, and if any of the entries are not\n        \/\/ in B, add them to the result dictionary.\n\n        foreach (KeyValuePair&lt;T, U&gt; kvp in dicA)\n        {\n            \/\/if (!dicB.Contains(kvp))\n            if (!(dicB.TryGetValue(kvp.Key, out var val) &amp;&amp; dicB[kvp.Key].Equals(kvp.Value)))\n            {\n                dicAExceptB[kvp.Key] = kvp.Value;\n            }\n        }\n    }\n}<\/pre>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>private static void DiffDictionaries&lt;T, U&gt;(  &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,106],"tags":[],"class_list":["post-2648","post","type-post","status-publish","format-standard","hentry","category-c","category-devlog"],"_links":{"self":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2648"}],"version-history":[{"count":2,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2648\/revisions"}],"predecessor-version":[{"id":2650,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/posts\/2648\/revisions\/2650"}],"wp:attachment":[{"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clonefactor.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}