I have
IDictionary<string,object> d1;
Dictionary<string, object> d2;
I need to remove from d1 all entries that are not in d2.
I know I can do this with a for loop etc but that’s so last century; I want to do it right.
I got to
d1.Where(x => {return d2.ContainsKey(x.key);});
but dont know what to do next
LINQ isn’t designed to modify existing elements – but you could always create a new dictionary. For example:
Or:
As others have said, if you’re more keen on doing a
Removeoperation, I’d just loop. For example:(I’m not sure why you used a statement lambda in your sample code, by the way.)