You asked yourself why you were always taught that it is a good idea to make members private?
This is because (among other reasons) it is detail . A detail of "storing data in memory", and this is an unimportant detail for any object that wants to receive or install data. Other classes do not need to worry about whether he can somewhere access a certain memory slot - he just needs an interface for which he can pass or receive a value - there are getters and setters or properties.
By separating the property from the "memory-based memory" part, we have many advantages. First of all, we can redefine the behavior of getting and setting without violating any code that uses the property. We can also use the property as an abstraction to retrieve data for several different implementations. This becomes extremely useful for testing / bullying behavior and providing alternative storage. If other classes depend on the implementation details of "memory", you cannot change the behavior of your class without breaking it.
Before the auto properties appeared, we will usually store the field and create a getter and setter for encapsulation for the reasons described above. An automatic property automates this for us. We could write code that usually uses fields everywhere in the code, but we do it with the idea "I will do this as a field for now, but it can be changed later if the criteria changes."
Since the class knows about this own implementation, it is usually a senseless desire to create private properties of a car, you do not hide already known details. Protected auto properties can be useful if you need to subclass.
As for situations in which they should be avoided: when you want read-only data. (data that will not be changed after the creation of the object). Auto properties lack syntax to create an automatic property supported by read-only data.
source share