I asked similar question here , I am wondering how you can achieve same result with LINQ
PREVIOUS QUESTION
Rules
Get values from dic2 where key match but values does not match or key is missing in dic2.
Don’t need to iterate through dic2 for missing/different values in dic1.
LINQ CODE
can result and missinkeu can combinstrong texte in one?
private void Compare(SortedDictionary<string, List<foo>> dic1, SortedDictionary<string, List<foo>> dic2)
{
var result= from c in dic1
where dic2.ContainsKey((c.Key) && !dic2[c.key]Equals(c.Value)
select p.Value;
var missingkey =from c in dic1
where !dic2.ContainsKey((c.Key)
select p.Value;
}
Do you just mean:
when the key is there the second match is tested. Note however, that this will only (as written) do a reference test on the lists – it won’t compare individual elements. It is hard to tell if that is what you mean since the code example in the linked post is… “unclear” (in that it attempts to add
fooas value forList<foo>).If you need to test the individual values:
(which assumes a sensible
Equalsimplementation onfoo.