Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Explicitly Request Boxing

You can explicitly request boxing by assigning a variable to a variable of type Object.

Example

// vcmcppv2_explicit_boxing3.cpp
// compile with: /clr
using namespace System;

void f(int i) {
   Console::WriteLine("f(int i)");
}

void f(Object ^o) {
   Console::WriteLine("f(Object^ o)");
}

int main() {
   float i = 22.22;
   i = 323.5654;
   Object ^ O = i;   // forces i to be boxed
   f(i);
   f( (Object^)i );  // boxes i
}

Output

f(int i)
f(Object^ o)

See Also

Community Additions

ADD
Show:
© 2015 Microsoft