Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

variables - 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 .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...