Click here to Skip to main content
15,906,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got following code in my project . I am new to c#. Please explain the concept behind this ..!!


m_sSearchText = m_sSearchText == "" ? "eyeglasses" : m_sSearchText;

Thanks..!!
Posted

It means

C#
if(m_sSearchText == "" )
{
m_sSearchText="eyeglasses";
}
else
{
m_sSearchText=m_sSearchText;
}


It is called "ternary if operator". More details here http://msdn.microsoft.com/en-us/library/ty67wk28(v=vs.80).aspx[^]
 
Share this answer
 
It means if your m_sSearchText is empty than by default it will take the value as "eyeglasses" else it will take the value of m_sSearchText.
Its a conditional statement. The syntax is.
variable=="value"?true:false
In Your case..
variable-->m_sSearchText
value-->""
true-->"eyeglasses"
false-->m_sSearchText
 
Share this answer
 
It is so simple

m_sSearchText == "" ? "eyeglasses" : m_sSearchText;

now the above line have a unary condition
means if your textbox "m_sSearch.Text" does not have any value then above line of code returns "eyeglasses"

Suppose your textbox named "m_sSearch.Text" have any value like "somevalue"
then it returns "somevalue"

another explanation:

"m_sSearchText == "" " if this is true then returns "eyeglasses"
else m_sSearch.Text


Sorry for my bad English
I hope you understand
 
Share this answer
 
Comments
k@ran 2-Mar-13 0:58am    
thanks all..
bkthebest 2-Mar-13 1:09am    
sorry
it was confusion

the condition is called ternary condition not unary condition
sorry all

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