String concats in .NET ultimately resolve to calls to one of the overloads of the static String.Concat methods. This is an optimization to reduce the number of temporary strings that would otherwise be created when mutliple concatenations occur in a single statement.
In short the reason this works is because a number of the String.Concat overloads will accept object
in the argument list and since an int, float etc. are in essence objects they can be passed to the Concat overload that accepts one or more object
parameters. Internally Concat of basically does a .ToString()
on the incomming object therefore turning your int
into it's string representation.
In your specific example
string st = "" + 12;
The compiler will reconize that the first string is empty and simply call the String.Concat(object)
overload. Which will convert the integer 12 to a string and assign it to st
.
This overload is called because the integer can be implicitly boxed to fit into the object type and therefore satisfy the method overload selection.