I wonder if boxing is taking place in order for ToString() to be called on the integer literal (5):

5.ToString();

Oh, and if not, what is taking place in order for the CLR to be able to call the ToString() method?

1

There are 1 best solutions below

8
On BEST ANSWER

No, that doesn't require boxing - because int overrides ToString. The compiler can determine exactly which method will be called, so it doesn't need to go through virtual dispatch. It doesn't even use callvirt - that call will correspond to IL of

call instance string [mscorlib]System.Int32::ToString()

If you don't override ToString() (etc) in a struct, then calls to the virtual method will require boxing.