默认键值对 [英] The default for KeyValuePair
本文介绍了默认键值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类型的对象的IEnumerable< KeyValuePair< T,U>> keyValueList
,我使用
I have an object of the type IEnumerable<KeyValuePair<T,U>> keyValueList
, I am using
var getResult= keyValueList.SingleOrDefault();
if(getResult==/*default */)
{
}
else
{
}
我如何检查是否的getResult
是默认的,如果我不能找到正确的元素?
How can I check whether getResult
is the default, in case I can't find the correct element?
我无法检查它是否是空
还是不行,因为 KeyValuePair </ code>是一个结构。
I can't check whether it is null
or not, because KeyValuePair
is a struct.
推荐答案
试试这个:
if (getResult.Equals(new KeyValuePair<T,U>()))
或本
if (getResult.Equals(default(KeyValuePair<T,U>)))
这篇关于默认键值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文