How to: Boxing 來明確要求
您可以將變數指派給型別的變數,以明確要求 boxing 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
}