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

Built-In ?=-Operator in C# #11394

Closed
therealhappy opened this issue May 18, 2016 · 2 comments
Closed

Built-In ?=-Operator in C# #11394

therealhappy opened this issue May 18, 2016 · 2 comments
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue

Comments

@therealhappy
Copy link

A built-in operator like '?=' to assign a value to variable, if the current value is null.

The expected behavior

Instead of writing

    List<short> listOfNumbers = null;
    [...]
    if (listOfNumbers == null)
    {
        listOfNumbers = new List<short>();
    }

Simply write this

    List<short> listOfNumbers = null;
    [...]
    listOfNumbers ?= new List<short>();
@dsaf
Copy link

dsaf commented May 18, 2016

#10556, #10249, #9529, #8894, #5163, #3366, #205

@HaloFour
Copy link

listOfNumbers = listOfNumbers ?? new List<short>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

4 participants