" +" operator c# MONO 2.10.12

I just found very strange thing in my code. By mistake I have put as an index something like this:

int a = 1;
int b = 1;

Dictionary<int, SomeClass> dic = new Dictionary<int, SomeClass> ();

dic[a -+ b].Field = 0;

As you can see there is "-+" opperator that really works as "-". Anyway the code was having good time, was compiling until I found it.

It is part of code in Unity3d for game that I am working on now.

The question is: is it normal? Or this is know bug in mono 2 and was fixed. I cannot find any info about it.

Jon Skeet
people
quotationmark

There's nothing strange about this, and there isn't a -+ operator. There's a unary + operator and a binary - operator. Just add parentheses and some spacing to make it clearer:

int a = 1;
int b = 1;
int c = a -+ b;
int d = a - (+b); // Same as above

Note that you can use +- as well, with the unary - operator and the binary + operator:

int e = a +- b;
int f = a + (-b); // Same as above

And while you can't use ++ or -- like this, because those really are separate operators, you can add a space:

int g = a + + b;
int h = a + (+b); // Same as above

int i = a - - b;
int j = a - (-b); // Same as above

You can also have multiple unary operators chained together, for real craziness:

int k = a +-+-+-+ b;
int l = a + (-(+(-(+(-(+b)))))); // Same as above

people

See more on this question at Stackoverflow