How to check if a variable is a default value of KeyValuePair?

643 viewsSoftware & Technologyc#
0

I have a bit of an awkward example but I am trying to extract a value from a dictionary if the key contains a substring. I have this part working, but I need to know when it does not find a match. The response from this request does not seem to accept a null. Here is the code that I am using to find a value from the dictionary.

This does what I want, but there will not always be a match. Sometimes result will be empty and I don’t know how to verify this.

How do i check if a KeyValuePair object contains the default value that would be returned for a miss with the FirstOrDefault query?

Edited question
0

I don’t have an explanation as to why the second option you tried does not work as it is more or less the same thing as this. The following code should allow you to check whether a KeyValuePair item is the default value.

 

Changed status to publish