Assuming the key and values, their equal and hash methods are applied correctly, to test for equality What is the most concise and efficient way of two dictionaries?
In this context, the two dictionaries are similar, if they are the set of the same key (not the order is important), and for each such key, they agree on the value.
Compare public hair 1 & lt; Vaccines, TVs & gt; (Dictionary & lt; vaccine, TVLux> DC1, dictionary & TT; TKE, TVLux> DC2) {return DC1. Orderbay (x = & gt; x) serial number (dick 2. orb (x = & gt; x.key)); } Compare public hair 2 & lt; TKey, TValue & gt; (Dictionary & lt; TKey, TValue & gt; dic1, dictionary & lt; TKey, TValue & gt; dic2) {return (dic1.Count == dic2.Count & dic1.Intersect (dic2).) Equal (dic1.Count)); } Compare public hair 3 & lt; TKey, TValue & gt; (Dictionary & lt; TKey, TValue & gt; dic1, dictionary & lt; TKey, TValue & gt; dic2) {Return (dic1.Intect (dic2) .ount (). Equals (dic1.Union (dic2). () )); }
dic1.Count == dic2.Count & amp; ! Dic1.Except (dic2) .Any ();
Comments
Post a Comment