Are ref and out in C# the same a pointers in C++?

后端 未结 7 460
挽巷
挽巷 2021-01-05 04:00

I just made a Swap routine in C# like this:

static void Swap(ref int x, ref int y)
{
    int temp = x;
    x = y;
    y = temp;
}

It does t

7条回答
  •  悲哀的现实
    2021-01-05 04:30

    ref and out are only used with function arguments to signify that the argument is to be passed by reference instead of value. In this sense, yes, they are somewhat like pointers in C++ (more like references actually). Read more about it in this article.

提交回复
热议问题