patterncsharpCritical
The default for KeyValuePair
Viewed 0 times
keyvaluepairforthedefault
Problem
I have an object of the type
How can I check whether
I can't check whether it is
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:
or 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.