什么是“使用” :,? "等...在C#中 [英] what is the use of " : ,? " etc... in C#
本文介绍了什么是“使用” :,? "等...在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到了一些代码....
cmbPosition.SelectedValue == null ? 0 :cmbPosition.SelectedValue;
< ; pre lang =c#> bnk.PartyWise = Convert.ToBoolean(cmbParty.SelectedIndex == -1?false:true);
i没有得到代码的含义......
又有什么用?,:符号?????
如何使用符号?????
谢谢
解决方案
这个
< pre lang =c#> cmbPosition.SelectedValue == null ? 0 :cmbPosition.SelectedValue;
等于:
if (cmbPosition.SelectedValue == null )
{
return 0 ;
}
其他
{
返回 cmbPosition。的SelectedValue;
}
和此:
bnk.PartyWise = Convert.ToBoolean(cmbParty.SelectedIndex == -1? false : true )
等于:
if (cmbParty.SelectedIndex == -1)
{
bnk.PartyWise = false ;
}
其他
{
bnk.PartyWise = true 跨度>;
}
i saw some coding like ....
cmbPosition.SelectedValue == null ? 0 : cmbPosition.SelectedValue;
<pre lang="c#">bnk.PartyWise = Convert.ToBoolean(cmbParty.SelectedIndex == -1 ? false : true);
i did't got the meaning of the code...
and what is the use of ?,: symbols ?????
how to use that symbols ?????
Thanks
解决方案
this
cmbPosition.SelectedValue == null ? 0 : cmbPosition.SelectedValue;
is equal to:
if (cmbPosition.SelectedValue == null) { return 0; } else { return cmbPosition.SelectedValue; }
and this:
bnk.PartyWise = Convert.ToBoolean(cmbParty.SelectedIndex == -1 ? false : true)
is equal to:
if (cmbParty.SelectedIndex == -1) { bnk.PartyWise = false; } else { bnk.PartyWise = true; }
这篇关于什么是“使用” :,? "等...在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文