Fundamentally, the behavior of the ++
operator in i++.ToString()
is no different from its behavior when calling any other function that takes i
as a parameter. For example, you would fully expect the original value of i
to be passed if you called SomeFunction(i++)
.
Consider, for example, an extension method:
public static class GoofyExtensions
{
public static string Frob(this int x)
{
return x.ToString();
}
}
Now, that can be called as if it were an instance method:
var s = i++.Frob();
The compiler turns that into a call to the static Frob
method:
var s = GoofyExtensions.Frob(i++);
It would be pretty surprising to find that i++.Frob()
returned a different value than i++.ToString()
.
The point here is that although ToString()
is a method without parameters, internally all instance methods have an implicit parameter: the instance. If you examine the generated MSIL, you'll see that a reference to the instance is passed as a parameter to all instance methods. So i.ToString()
is in a very real sense a call to Int32.ToString(i)
.