c#中以下代码的含义是什么 [英] What is the meaning of following code in c#

查看:77
本文介绍了c#中以下代码的含义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有以下代码。我是c#的新手。请解释这背后的概念.. !!





m_sSearchText = m_sSearchText ==? eyeglasses:m_sSearchText;



谢谢.. !!

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..!!

推荐答案

这意味着



It means

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





它被称为三元运算符。更多详细信息,请访问 http://msdn.microsoft.com/en-us/ library / ty67wk28(v = vs.80).aspx [ ^ ]


这意味着如果你的m_sSearchText是空的,那么默认情况下它会将值作为眼镜,否则它将取m_sSearchText的值。

它是一个条件语句。语法是。

变量==值?true:false

在你的情况下..

变量 - > m_sSearchText

值 - >

true - >眼镜

false - > m_sSearchText
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


这么简单



m_sSearchText ==? eyeglasses:m_sSearchText;



现在上面的行有一元条件

表示你​​的文本框m_sSearch.Text没有任何值,然后上面的代码行返回眼镜



假设您的名为m_sSearch.Text的文本框具有任何值somevalue

然后它返回somevalue



另一种解释:



m_sSearchText ==如果这是真的然后返回眼镜

其他m_sSearch.Text





抱歉我的英文不好

我希望你理解
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


这篇关于c#中以下代码的含义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆