Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
i saw some coding like ....

C#
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
Posted
Updated 13-Dec-13 18:45pm
v4
Comments
BillWoodruff 14-Dec-13 2:36am    
If you select the "?" in the code examples you show and hit F1, Visual Studio Help will take you to the documentation for the conditional operator syntax (test) ? (if true) : (if false);

1 solution

this
C#
cmbPosition.SelectedValue == null ? 0 : cmbPosition.SelectedValue;

is equal to:
C#
if (cmbPosition.SelectedValue == null)
{
    return 0;
}
else
{
    return cmbPosition.SelectedValue;
}

and this:
C#
bnk.PartyWise = Convert.ToBoolean(cmbParty.SelectedIndex == -1 ? false : true)

is equal to:
C#
if (cmbParty.SelectedIndex == -1)
{
    bnk.PartyWise = false;
}
else
{
    bnk.PartyWise = true;
}
 
Share this answer
 
v5
Comments
An@nd Rajan10 14-Dec-13 0:54am    
thanks ....
some coding using like double question mark (??), what is that?
adriancs 14-Dec-13 0:56am    
for example?
An@nd Rajan10 14-Dec-13 1:02am    
ya i understand .....

Convert.ToDouble(txtTotPremium.Text == null ? "0" : txtTotPremium.Text) + Convert.ToDouble(dgvReleaseOrder.Rows[row].Cells["PremiumAmt"].Value == null ? "0" : dgvReleaseOrder.Rows[row].Cells["PremiumAmt"].Value))
An@nd Rajan10 14-Dec-13 1:03am    
thank u so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900