boxing ???

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi,


I declare an integer and use the ToString()-method (see code below) . That
works fine

Now, using the same integer do I use the GetType()-method --> compiler error
==> error C3610: 'Int32': value type must be 'boxed' before method 'GetType'
can be called

How come ? Both methods are inherited from System::Object, but must be used
differently ???

Code sample :
int i = 10;
Console::WriteLine(i.ToString()); ==> OK
Console::WriteLine(i.GetType()->Name); ==> compiler error

thanks
Chris
 
Both methods are implemented on System::Object, but ToString is implemented
specifcally for Int32 which is why you can call it without boxing.

Ronald Laeremans
Visual C++ team
 
Back
Top