How to: Explicitly Request Boxing
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at How to: Explicitly Request Boxing.
You can explicitly request boxing by assigning a variable to a variable of type Object.
// 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() {
int i = 5;
Object ^ O = i; // forces i to be boxed
f(i);
f(O);
f( (Object^)i ); // boxes i
}
f(int i) f(Object^ o) f(Object^ o)
Show: