Hacker News new | ask | show | jobs
by jayd16 1982 days ago
You could use an explicit private readonly field and a property getter, or even just a public readonly field. I would argue its only sugar.
3 comments

Are you referring to the init only setters?

If so, it isn’t just sugar, they added a new hook for it in the internals, rather than just relabelling a technique to accomplish a similar (but not equal) end.

It doesn't scale that well, as you need ctor parameters for every property, so API additions may also be breaking changes.
well that would be different to instantiate tough. it would be Class(1, 2, 3) instead of Class { Value1=1, Value2=2, Value3=3, }

actually record types are more syntactic sugar around what you said than initonly, which opens up a new way of writing code