Reputation: 11
What does this mean: String^ var_name
? I can do this only in CLR C/C++. And I know that ^
is a XOR.
What is the difference between:
`string name` and `String^ name`?
Upvotes: 0
Views: 421
Reputation: 334
It is actually a heap pointer /handle to managed heap object. It is a pointer or index with no visible type attached to it.
Check these links out. Heap , How to Declare Handle
Upvotes: 0
Reputation: 14510
It is the handle to object operator. It declares a managed pointer.
They seem like normal pointers but you don't have to free them.
From here:
The handle declarator (
^
, pronounced "hat"), modifies the type specifier to mean that the declared object should be automatically deleted when the system determines that the object is no longer accessible.A variable that is declared with the handle declarator behaves like a pointer to the object.
Upvotes: 2
Reputation: 758
String^ is managed string. ^ operator means that variable is an managed reference.
Upvotes: 0
Reputation: 409266
It's a managed pointer, i.e. a pointer which is garbage collected. Think of them as normal pointers, but you don't have to free them.
You have to use gcnew
to allocate those pointers explicitly, not new
.
Upvotes: 1