- 1

What is the difference between setters/getters and properties?

It seems that they achieve the same thing

28th Sep 2016, 6:14 AM
dejanualex
dejanualex - avatar
3 Answers
+ 2
thanks Ousmane ,
28th Sep 2016, 2:04 PM
dejanualex
dejanualex - avatar
+ 1
They're the same thing essentially but a slight difference which people take seriously nowadays due to the Object Oriented Manner. You should only(or is most cases) use getters and setters when your properties are encapsulated(data hiding). i.e private string str = "test"; is only accessible within the class so its encapsulated, however if you want other classes to access that property and allow them to modify then you have to provide the getters and setters. Finally you might say "why didnt we make it public in the first place", nope this doesnt work the same way and for more info please check tutorialspoint.
28th Sep 2016, 9:38 AM
Ousmane Diaw
0
You're welcome! Happy coding!
28th Sep 2016, 2:31 PM
Ousmane Diaw