Proposal: Allow optional property initialization with fallback to the default value #1369
Replies: 4 comments
-
Why not just use |
Beta Was this translation helpful? Give feedback.
-
I like |
Beta Was this translation helpful? Give feedback.
-
@jnm2 What I mean is... My understanding was that Additionally, I would prefer So I see it as "initialize the property to this value unless this value is the default value, because the programmer doesn't want that property to be initialized with that default value." |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Can we get this syntax
[Property Name] ?= [Some Value]
, when using the object initializer, to only override a property's default value if[Some Value]
is notnull
ordefault
?Example / Explanation
Currently, you can do this...
This is really nice, because it allows you to initialize a property with a default value. For example...
Suppose, that while refactoring my code I notice that I frequently make connections and add them to some dictionary that maps their name to themselves. To clean things up a bit I might do the following...
However, now I've lost the defaults set in
Connection
...I am proposing the using the following syntax to solve this issue...
Beta Was this translation helpful? Give feedback.
All reactions