Reputation: 12526
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?
Upvotes: 0
Views: 84
Reputation: 1502186
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.
Upvotes: 1