3 ms·
You don't need getters and setters in c#. If you don't have any side effect in a read-write property you can just use an automatic property. The same for read o
by tigershark 10y ago
You don't need getters and setters in c#. If you don't have any side effect in a read-write property you can just use an automatic property. The same for read only properties that don't need to be recalculated on the fly. And I hope that I don't need to explain why using a write only property is almost always a code smell.
In the other cases you can use a normal property with a backing field.
If your code is well written and you use the appropriate tools, only rarely you need normal properties (that are as annoying as getters/setters).
What do getters and setters offer that public fields don't?
Properties offer exactly the same advantage as getters and setters, fields encapsulation https://en.m.wikipedia.org/wiki/Field_encapsulation https://en.m.wikipedia.org/wiki/Field_encapsulation
No wonder that you don't understand properties if you don't know why getters and setters are useful.