This has to do with operator precedence. Let's take for example the expression:
string s = "";
s += '0' + '1';//here + has higher precedence than +=
Here + has higher precedence than += so the characters '0' and '1' are group together as ('0' + '1'). So the above is equivalent to writing:
s+=('0' + '1');
Next, there is implicit conversion from char to int of both '0' and '1'. So '0' becomes the decimal 48 while the character '1' becomes decimal 49.
So essentially the above reduces to:
s+=(48 + 49);
or
s+=(97);
Now 97 corresponds to the character a and therefore the final result that is appended to the string variable named s is the character a.
Now lets apply this to your example:
string s = "";
s += 'a' + 'b';
First due to precedence:
s+=('a' + 'b');
Second implicit conversion from char to int happens:
s+=(97 + 98);
So
s+=195;
So the character corresponding to decimal 195 will be appended to string s.
You can try out adding and subtracting different characters to confirm that this is happening.
Why does the first example append the char and the second does not?
So the fundamental reason is operator precedence.
s = s + ('a'+'b'). You're adding the two char together first before appending them.'a'+'b'is an integer 195. Trys += "ab".chars are an integer type with special display rules that allow you to see them as characters. Unfortunately, in this case, this means when you add twochars you don't append them, you sum the two numeric values of character's encoding.(s +='a') +='b';, isn't it?+=as a function and you won't be far wrong. The parameters of the function are resolved before the call. Oh wait. Are you suggesting a code change, @康桓瑋 ?