Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would +- do as an operator in c#

Tags:

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?

like image 654
Vasa Serafin Avatar asked Aug 08 '15 08:08

Vasa Serafin


People also ask

What is << in C?

<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .

What is this operator called ?:?

In computer programming, ?: is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages. It is commonly referred to as the conditional operator, inline if (iif), or ternary if.

What is an operator used for?

Definition and Usage. The len() function returns the number of items in an object. When the object is a string, the len() function returns the number of characters in the string.


1 Answers

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 +).

like image 56
Nasreddine Avatar answered Oct 10 '22 02:10

Nasreddine