First off, this has nothing to do with MessageBox.Show
. This has everything to do with the +
operator. The result of string + object equals a string.
There are a number of overloads to the + operator in the language (and you can also add your own for user defined types). There are only two that takes an object
as a parameter, that is operator+(string, object)
and operator+(object, string)
. In both cases the body of the implementation of the operator will call ToString
on the object
parameter and then use string.Concat
to produce the result.
Since your variable is an integer and it is using operator+
with string
as the first parameter it will match operator+(string, object)
an no other candidates.