class Program {
static void Main(string[] args) {
Int32 i = 123;
Double d = 123.456;
FunPrint(i);
FunPrint(d);
}
static void FunPrint(object obj) {
Console.WriteLine(obj);
}
}
My understanding of this sample is that FunPrint()
first creates a new object and builds it based on the value of the ValueType being passed (Int32
in this case). Second, the Object.ToString()
is called and correctly displays ValueType-specific string formatting.
Value types do not contain virtual functions so...
What I do not understand is how the Object
knows what type it is holding internally in order to do the proper string formatting.