C# reference assignment operator?

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

    I once wrote a prototype of a version of C# that had that feature; you could say:

    int x = 123;
    ref int y = ref x;
    

    and now x and y would be aliases for the same variable.

    We decided to not add the feature to the language; if you have a really awesome usage case I'd love to hear it.

    You're not the first person to ask about this feature; see Can I use a reference inside a C# function like C++? for more details.

    UPDATE: The feature will likely be in C# 7.

提交回复
热议问题