How to rearrange legend order in ggplot

For this C#, a==true:

bool a = "hello" +   '/' + "world" == "hello/world";

And for this C#, b==true:

bool b = "hello" + + '/' + "world" == "hello47world";

I'm wondering how this can be, and more importantly, why did the C# language architects choose this behavior?


The second + is converting the char to an int, and adding it into the string. The ASCII value for / is 47, which is then converted to a string by the other + operator.

The + operator before the slash implicitly casts it to an int. See + Operator on MSDN and look at the "unary plus".

The result of a unary + operation on a numeric type is just the value of the operand.

I actually figured this out by looking at what the + operators were actually calling. (I think this is a ReSharper or VS 2015 feature)

enter image description here

enter image description here


That's because you are using the unary operator +. It's similar to the unary operator -, but it doesn't change the sign of the operand, so the only effect it has here is to implicitly convert the character '/' into an int.

The value of +'/' is the character code of /, which is 47.

The code does the same as:

bool b = "hello" + (int)'/' + "world" == "hello47world";

Why, I hear you ask, is the char specifically treated to the operator int operator +(int x) rather than one of the many other fine unary + operators available?:

  • The unary operator overload resolution rules say to look at user-defined unary operators first, but since char doesn't have any of those, the compiler looks at the predefined unary + operators.
  • Obviously none of those take a char either, so the compiler uses the overload resolution rules to decide which operator (of int, uint, long, ulong, float, double decimal) is the best.
  • Those resolution rules says to look at which is the best function... which pretty much says to look at which argument type offers the best conversion from char.
  • int beats out long, float and double because you can implicitly convert int to those types and not back.
  • int beats uint and ulong because... the best conversion rule says it does.