且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是“使用” :,? "等...在C#中

更新时间:2022-10-15 20:14:21

这个

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;
}