Hacker News new | past | comments | ask | show | jobs | submit login

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.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: