有没有像“=+"这样的东西?操作员? [英] Is there such thing as a "=+" operator?
本文介绍了有没有像“=+"这样的东西?操作员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道为什么 +=
有效而 =+
无效.假设我有这样的代码:
I'm wondering why is +=
valid but =+
is not valid. Let's say I have code like this:
string strOne = "World!";
strOne =+ "Hello ";//strOne = "Hello " + strOne; not valid
//Error: Operator '+' cannot be applied to operand of type 'string'
//Intended Output: Hello World!
string strTwo = "Hello ";
strTwo += "World!";//strTwo = strTwo + "World!"; valid
//Output: Hello World!
我也不确定 strOne =+ "Hello ";
是否与 strOne = "Hello " + strOne;
相同.是否有任何关于 =+
无效或语法不正确的规则?
I'm also not sure whether strOne =+ "Hello ";
is same as strOne = "Hello " + strOne;
. Are there any rules on why =+
is not valid or cannot be syntactically correct?
推荐答案
简单的答案是否定的,没有 =+
运算符.你必须这样做
The simple answer is no, there is not a =+
operator. You would have to do
strTwo = "Hello " + strTwo;
不存在的部分原因可能是 +
是数字类型的有效一元运算符.
Part of the reason that there isn't could be that +
is a valid unary operator for number types.
var intValue = +2;
这篇关于有没有像“=+"这样的东西?操作员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文