Note. Despite your question: βI need to compare values in both dictionariesβ (my underscore), your example seems to demonstrate just a comparison of keys, so I went with that. If these are the values ββyou need to compare, you can give an example of what you mean and if they are easily convertible or comparable ...
If you are actually comparing keys, you can simply use the .Keys
property of the dictionary, which returns an IEnumerable<TKey>
, which you can use in your linq ...
eg:
var expectedOutput = newDic.Keys.Except(oldDic.Keys);
It relies on a key of the same type, but it goes without saying if you are comparing. Of course, there is nothing that would prevent you from first converting their types if you do this with different types.
Also, if you want to get values ββin one of the dictionaries, you can do something like:
var newDicValues = expectedoutput.Select(x=>newDic[x]);
Or, you know, do any other things you like. :)
Chris source share