+ 1
When it comes to a class what is the difference between declaring a public variable, and a private one plus using an auto implemented property?
I mean i don't see the difference, I could get and set the variable value from the main program in both cases, can you help me? I know there must be a reason
2 Antworten
0
You most likely use that when you want to restrict setting and getting for other classes and/or want to do something else too when setting or getting a variable. For example save to the database when setting.
0
It's about scope of given object. See topic encapsulation. Public access method or variable can be accessed from any point in your application. With private access you restrict access to given class only