Welcome to the Treehouse Community
Looking to learn something new?
olu adesina23,007 Points
what is the purpose of auto properties
Steven Parker i understand how within curly braces of the getters and setters of properties we can add additional code like conditional statements to control how the variables are used and displayed.
but with auto properties no additional logic is required in the property accessors so how is this different from a field which is public. I can access it to get information and set it i can make it read only
why now use a public field instead
Steven Parker220,451 Points
Two advantages to a property come to mind:
- properties can be virtual and overridden
- you can give a property's setter different access (protected or private)
Also, more debugging features are available to properties, such as setting a breakpoint on the setter.
And try posting questions without tagging anyone intially, there are several folks around who like to help. You tag someone later if you don't get a good answer in a day or so.