I know I'm not asking this quite right, either. Please help me better form my question.
I'm having a bit of a hard time getting my mind wrapped around handles -- in some ways, it looks like pointers. But unlike pointers, it seems like I can assign values directly to the handle variable, and it affects the underlying data value, not the handle itself.
The test code clearly shows that I get the same value whether I use the handle, or if I "dereference" the handle to get to the data. Clearly, this wouldn't work with unmanaged pointers. What am I not understanding?
#include <iostream>
int main()
{
int ^y;
int ^a, ^b, ^c;
long x;
y= gcnew int(100);
a=y;
b=y;
c=y;
c= gcnew int(200);
b= 300;
System::Console::WriteLine(y); // returns 100 (instead of something pointer-like)
System::Console::WriteLine(*y); // also returns 100
System::Console::WriteLine(a); // 100
System::Console::WriteLine(b); // 300
System::Console::WriteLine(c); // 200
x = static_cast<long>(y);
*y = 10;
System::Console::WriteLine(x); // 10
System::Console::WriteLine(y); // 10
System::Console::WriteLine(*y); // 10
}
Edit to add -- I suspected that WirteLine might have done the dereferencing for me, but I would have expected the static cast to long would not. Is this related to autounboxing as welll?