//string concatenation
string s = "Hello";
s += " world.";
Console.WriteLine(s);
//Output: "Hello world."
In other words, x += y is the same as x = x + y.
I would like to overload (or declare a new operator?) so that x += y is the same as x = y + x. I just want to reverse the order. So in MS's example, the output would be " world. Hello"
My preferred solution would be creating a "=+" operator, which would accurately mimic the desired behavior. The second-best would be overloading the += operator. Are either of those possible, and if so how would I go about that?
I would say that if one were to redefine += to behave as suggested in the OP it would cause great confusion for anyone reading or writing the code as well as possibly confusing the compiler and causing many problems along the way.
The opposite suggested in post #3 might not be so bad but would still confuse anyone reading the code.
Bookmarks