PART I
C h a p t e r 1 1 :
I n h e r i t a n c e
309
PART IPART I
unboxing automatically handle the details for the value types. Furthermore, because all
types are derived from
object
, they all have access to
object
’s methods. For example,
consider the following rather surprising program:
// Boxing makes it possible to call methods on a value!
using System;
class MethOnValue {
static void Main() {
Console.WriteLine(10.ToString());
}
}
This program displays 10. The reason is that the
ToString( )
method returns a string
representation of the object on which it is called. In this case, the string representation
of 10 is 10!
Do'stlaringiz bilan baham: |