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

后端 未结 7 523
挽巷
挽巷 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:27

    Reference parameters in C# can be used to replace one use of pointers, yes. But not all.

    Another common use for pointers is as a means for iterating over an array. Out/ref parameters can not do that, so no, they are not "the same as pointers".

提交回复
热议问题