C# Properties And Auto-Properties
Turning a variable into a property allows more control over how accessible the property is, and the optional addition of functionality on value changes.
Properties:
Properties are very similar to normal variables, and can be considered a variant which allows finer control over how accessible the variable is. They also provide the option to add in additional functionality which will be executed when the value is read or set.
When programmers talk about “Getters and Setters”, they are most likely talking about properties. “get” and “set” are the keywords used to create a property.
Auto-Properties:
Something you may not know, or may have heard but not understood, is the term “Auto-Property” or “Auto-Properties”.
Auto-properties are:
- Variables that allow finer control over how accessible their “read” and “set” functionality is.
And
- Properties that do not allow any additional functionality to be added when the value is “read” or “set”.