|
|
|
|
|
by Fr0styMatt
4574 days ago
|
|
While it would seem that getters and setters vs public fields are very similar, there's a catch at least in the C# world - if you have a raw public field and later decide to change it to a property, that breaks your public interface and you have to rebuild stuff against your library. Thankfully C# makes declaring getters and setters easy from the start, so it's not an issue to use them: public int SomeField { get; private set; } That gives you a public property called SomeField which can be retrieved, but which can only be set privately by the class. I'd hate having to write GetBlah and SetBlah; it's damn ugly. |
|