Why do we need a getter for just for example getting the field of an object in C#? Setter makes sense to me for its purpose, for example, to validate data, or add some algorithm when changing a field.

Dat Pham 1 Reputation point
2022-10-03T16:41:46.343+00:00

Why do we need a getter for just for example getting the field of an object in C#? Setter makes sense to me for its purpose, for example, to validate data, or add some algorithm when changing a field. I mean if we are going to get the value of the field, just make a public field and done.

Developer technologies | C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.