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

后端 未结 7 457
挽巷
挽巷 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:20

    The nice thing about using out is that you're guaranteed that the item will be assigned a value -- you will get a compile error if not.

提交回复
热议问题