Skip to content
Discussion options

You must be logged in to vote

As suggested in #2001, other proposals would lead to a nice syntax for this:

public Foo Foo 
{
    set; get => field ??= new Foo();
}

and they have the advantage of allowing flexibility around what is assigned when the field is null, rather than hard-coding new Foo() as your proposal would do.

Replies: 14 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by YairHalberstadt
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
9 participants
Converted from issue

This discussion was converted from issue #2003 on October 19, 2020 11:17.