Does the ^ symbol replace C#'s "ref" in parameter passing in C++/CLI code?

Viewed 25963

In C#, passing by reference is:

void MyFunction(ref Dog dog)

But in C++/CLI code examples I have seen so far, there is no use of ref but instead ^ symbol is used:

void MyFunction(Dog ^ dog)

Is the use of ^ symbol a direct replacement for ref when parameter passing? or does it have some other meaning I'm not aware of?

Additional Question: I also see a lot of:

Dog ^ myDog = gcnew Dog();

It looks like it's used like * (pointer) in C++.. Does it work similarly?

Thanks!

5 Answers

3 Types in C++/CLI :

  1. Handle Type (^): Handle contain address of variable but which can be updated by runtime if it has to move variable around to maximize available free memory.
    Example: Person ^pp = gcnew Person(); // gcnew in C++/CLI is similar to new in C++.

  2. Reference Type (%): Reference alias of a variable. % in C++/CLI is Similar to & in C++.
    Example: int %ri = i; // ri is reference alias for i.
    Person %rPerson = *pp; // pp from point number 1

  3. Array Type ([]):
Related