在C#中联合运营? [英] Coalesce operator in C#?
本文介绍了在C#中联合运营?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我记得看到一些类似:三元运算符一>在C#中,只有有两个部分,并会返回变量的值,如果它不是空和默认值,如果它是。事情是这样的:
I think i remember seeing something similar to the ?: ternary operator in C# that only had two parts to it and would return the variable value if it wasn't null and a default value if it was. Something like this:
tb_MyTextBox.Text = o.Member ??SOME OPERATOR HERE?? "default";
这基本上相当于:
Basically the equivalent of this:
tb_MyTextBox.Text = o.Member != null ? o.Member : "default";
有没有这样的事情存在,还是我只是想象看到了这个地方?
Does such a thing exist or did I just imagine seeing this somewhere?
推荐答案
烨:
tb_myTextBox.Text = o.Member ?? "default";
<一个href="http://msdn.microsoft.com/en-us/library/ms173224(VS.80).aspx">http://msdn.microsoft.com/en-us/library/ms173224(VS.80).aspx
这篇关于在C#中联合运营?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文