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?
From the C# spec – section 7.7.4 Addition operator: