As we know, int has ToString() method which override the ToString() method of base type Object.
For this following code,
int x = 100;
object y = (object)x;
Console.Write(y.ToString());
(1) Whose ToString() would be called? int or object? WHY?
(2) How we can check/view the truth? By any debug/tool?
Int32.ToString() would be called, because ToString() is called virtually.
Int32.ToString() overrides Object.ToString(), so at runtime it effectively replaces Object.ToString().
And at runtime, y is a boxed int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With