C# reference assignment operator?

后端 未结 6 577
滥情空心
滥情空心 2020-12-11 08:28

for example:

        int x = 1;
        int y = x;
        y = 3;
        Debug.WriteLine(x.ToString());

Is it any reference operator inste

6条回答
  •  半阙折子戏
    2020-12-11 08:51

    You can use pointers like in C

        int x = 1;
        unsafe
        {
            int* y = &x;
            *y = 3;
        }
    
        Debug.WriteLine(x.ToString());
    

    (Note you have to compile with the unsafe flag)

提交回复
热议问题