[Proposal]: Shorthand property setter #4481
Replies: 6 comments 14 replies
-
What is the value of this? What problem does it solve?
This world declare a write-only property with an inaccessible field for storage, so the only code that can read the value will be using reflection. Doesn't seem to be widely useful. Note that this can't be equivalent to your alternative as the backing fields for autoproperties have inexpressible names to avoid name collisions. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
@theunrepentantgeek @jnm2 This: public int hello <= 100 * value; Is supposed to behave the same as this: private int _hello;
public int hello
{
get => _hello;
set => _hello = 100 * value;
} Thank you for your reply. |
Beta Was this translation helpful? Give feedback.
-
#140 would enable this syntax: public int Hello { get; set => field = 100 * value; } This wouldn't have the downside of secretly emitting a |
Beta Was this translation helpful? Give feedback.
-
The language team does not: #1278 (comment) |
Beta Was this translation helpful? Give feedback.
-
This could work well if only applied to public string Name {
get;
set <= value + " ";
} This would be rendered useless without #140, since its useless to get a value in a different way then setting it. If #140 is ever passed, then this syntax could be useful; public string Name {
get => field.Substring(0, file.Length - 1);
set <= value + " ";
} The fact that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Shorthand property setter
Summary
Easier way to quickly define a setter only property (Similar to the shorthand getter property feature) This feature assumes we want to have a default get method
Motivation
I think it makes sense because we already have the shorthand getter.
Detailed design
Its already there for the getter so why not have it for the setter.
Drawbacks
None that I can think of.
Alternatives
Using the normal set:
Unresolved questions
None that I can think of
Design meetings
Sorry but I'm not sure about this one either.
Beta Was this translation helpful? Give feedback.
All reactions