简体   繁体   中英

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

If this is the case though perhaps I could use a split[lengthsplit+-] instead?

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 +- 1lengthsplit + (-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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM