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

后端 未结 7 525
挽巷
挽巷 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

    The short answer is Yes (similar functionality, but not exactly the same mechanism). As a side note, if you use FxCop to analyse your code, using out and ref will result in a "Microsoft.Design" error of "CA1045:DoNotPassTypesByReference."

提交回复
热议问题