HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

The default for KeyValuePair

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
keyvaluepairforthedefault

Problem

I have an object of the type IEnumerable> keyValueList, I am using

var getResult= keyValueList.SingleOrDefault();
 if(getResult==/*default */)
 {
 }
 else
 {
 }


How can I check whether getResult is the default, in case I can't find the correct element?

I can't check whether it is null or not, because KeyValuePair is a struct.

Solution

Try this:

if (getResult.Equals(new KeyValuePair()))


or this:

if (getResult.Equals(default(KeyValuePair)))

Code Snippets

if (getResult.Equals(new KeyValuePair<T,U>()))
if (getResult.Equals(default(KeyValuePair<T,U>)))

Context

Stack Overflow Q#1641392, score: 690

Revisions (0)

No revisions yet.