[英]What would +- do as an operator in c#
I have researched into this extensively, but cannot seem to find anything in its regard. 我对此进行了广泛的研究,但似乎找不到任何东西。
If I was to use an if statement as a validation and needed to write something along these lines: 如果我要使用if语句作为验证,并且需要按照以下方式写点东西:
if(split[lengthsplit + 1] == "=" && split[lengthsplit - 1] == "=")
Could I write the above as the following with the same result: 我可以将以下内容写成相同的结果:
if(split[lengthsplit +- 1] == "=")
I cannot see the result of this and am wondering if in this case it would add a 1 and take it away or if it would try both scenarios first giving the ability to compress the validation down getting rid of the boolean operators to some degree. 我看不到结果,并且想知道在这种情况下是否会加1并取走它,还是先尝试两种情况都可以压缩验证,从而在某种程度上摆脱布尔运算符。
If this is the case though perhaps I could use a split[lengthsplit+-] instead? 如果是这种情况,也许我可以改用split [lengthsplit +-]?
Could I write the above as the following with the same result 我可以将以下内容写成相同的结果吗
No you can't because this lengthsplit +- 1
translates to lengthsplit + (-1)
because the -
here is considered a unary operator (and unary operators have higher precedence than the binary +
). 不,您不能,因为此lengthsplit +- 1
转换为lengthsplit + (-1)
因为-
在这里被认为是一元运算符(并且一元运算符的优先级高于二进制+
)。
lengthsplit +- 1
是lengthsplit + (-1)
lengthsplit +- 1
lengthsplit + (-1)
在“ C#”中没有“-+”或“ +-”运算符
There is no +-
operator. 没有+-
运算符。 The example you have provided is a perfect example of how not to use whitespace. 您提供的示例是如何不使用空格的完美示例。 If anything the + cancels itself out. 如果有的话,+会自行取消。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.