You are here beacause you probably got a Linq error, specifically Operator ‘==’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair
So if you wish to do something like this to KeyValuePair using Linq
1 2 3 4 5 6 |
var item = myDictionary.FirstOrDefault(x => x.Key == 123); if(item != null) { //blah blah } |
You will get this error
Operator ‘!=’ cannot be applied to operands of type ‘System.Collections.Generic.KeyValuePair
Since by default KeyValuePairs are struct.
To solve the issue we need to try out this
1 2 3 4 5 6 |
var defaultVal = default(KeyValuePair<int, string>); var item = myDictionary.FirstOrDefault(x => x.Key == 123); if(!item.Equals(defaultValue) { //blah blah } |
Hope this helps 🙂
Leave A Comment