Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# reference assignment operator?

for example:

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

Is it any reference operator instead of "=" on line:3, to make the x equal to 3 , if i assign y =3 .

like image 909
Cheung Avatar asked Dec 02 '22 01:12

Cheung


1 Answers

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.

like image 124
Eric Lippert Avatar answered Dec 17 '22 07:12

Eric Lippert