C# reference assignment operator?

后端 未结 6 569
滥情空心
滥情空心 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:36

    This is not exactly what you're asking, but I thought it might be helpful. If you want a pointer alias inside a function, you can use the ref keyword like such:

    public static void RefExample(ref int y)
    {
        y = 3;
    }
    
    main()
    {
        int x = 5;
        RefExample(ref x);
        Console.WriteLine(x); // prints 3
    }
    

提交回复
热议问题