❔ Please can someone explain me the point of using Automatic Properties get; set;
From what I understood, automatic properties get; set; should be used instead of public fields in classes (even though they do the same thing). If I want to customize properties later I can't use automatic properties anymore... So what is the point of using them?
6 Replies
You can later customize them without changing the external API
if you have an auto-prop and later turn it into a bodied-prop, its still a property, with the same name, and still has a getter and a setter. Its functionally identical, as far as other code is concerned
if you change something from a field to a property, it changes type as far as reflection is concerned, and several important tools rely on type metadata - serializers for example
Unless you require a setter for some crap serializer I would say the only important thing is get. Which is just syntactic sugar.
kool aid man bursts through
Immmmmutability
also, autoproperties still provide more accessibility control than fields
e.g.
{ get; init; }
or { get; private set; }
Yup
You cant see it but it's there!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.