Why is the integer converted to string in this case?
associativity, c#, evaluation, operators
Solution
From the C# spec - section 7.7.4 Addition operator:
String concatenation:
string operator +(string x, string y);
string operator +(string x, object y);
string operator +(object x, string y);
The binary + operator performs string concatenation when one or both operands are of type string. If an operand of string concatenation is null, an empty string is substituted. Otherwise, any non-string argument is converted to its string representation by invoking the virtual ToString method inherited from type object. If ToString returns null, an empty string is substituted.
Problem
What is happening below? ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; public class DotNetPad { public static void Main(string[] args) { int i = 10; string k = "Test"; Console.WriteLine(i+k); Console.WriteLine(k+i); } } ``` `i` is being converted to string in both cases. I am confusing myself with the idea of operator precedence (although this example doesn't show much of that) and evaluation direction. Sometimes evaluation happens from left-to-right or vice versa. I don't exactly know the science of how the expression is evaluated... Why is `i` converted to string in the above example, and not actually giving a compilation error?