Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: null-conditional assignment #10556

Closed
Ricciolo opened this issue Apr 14, 2016 · 2 comments
Closed

Proposal: null-conditional assignment #10556

Ricciolo opened this issue Apr 14, 2016 · 2 comments

Comments

@Ricciolo
Copy link

Hi guys!
Since we've null-conditional operator, why we cannot have a null-conditional assignment, like:

string var1 = "value1";
string var2 = null;
var1 ?= var2;`

Assert.AreEqual("value1", var1);

You may say that I can write the same thing using

string var1 = "value1";
string var2 = null;
var1 = var2 ?? var1;

but here I'm setting var1 to var1 even if not necessary.
With null-conditional assignment the compiler produce this code:

string var1 = "value1";
string var2 = null;
if (var2 != null) var1 = var2;

With null-conditional operator instead:

string var1 = "value1";
string var2 = null;
var1 = (var2 != null) ? var2 : var1;

What do you think?

@HaloFour
Copy link

Dupe of #10249, #9529, #8894, #5163, #3366 and #205.

The resolution of #205 was "won't fix", so I don't think that the operator is under consideration.

@Ricciolo
Copy link
Author

ops, sorry :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants