I had accidentally tried this, which compiles! So I was wondering what could this possibly mean.. google didnt help..
if (3 >+ 4)
dothis() //this is never hit btw..
if (3 >- 4)
dothis() //this is hit.
Both the code compile btw..
I had accidentally tried this, which compiles! So I was wondering what could this possibly mean.. google didnt help..
if (3 >+ 4)
dothis() //this is never hit btw..
if (3 >- 4)
dothis() //this is hit.
Both the code compile btw..
It parses as
3 > +4
and
3 > -4
So into the unary +
and unary -
operators.
If you want an interesting way to explore this, write
Expression<Func<int, int, bool>> func = (x, y) => x >+ y;
and then explore the resulting expression tree func
in the debugger. You'll see the unary operator in the tree.
Is 3 greater than 4?
Is 3 greather than -4?
If you're ever in doubt about what something is doing, write a little test app:
int i = +3;
int j = -4;
Console.WriteLine(i);
Console.WriteLine(j);
Console.WriteLine((3 > +4));
Console.WriteLine((3 > -4));
Try putting a semicolon after dothis() like
dothis();
Then watch what happens to the + and - operator. They will be shifted away from greater or less than sigh and move nearer to 4.
if (3 > +4)
dothis() //this is never hit btw..
//will never hit in the entire universe
if (3 > -4)
dothis() //this is hit
//will always be a hit
First becomes if 3 > +4 (Positive 4) which will always result in false.
Second becomes if 3 > -4 (Negative 4) which will always result in true.