Posts

Showing posts from November, 2017

FAQ

What is the primary purpose of a property ? - To guard access to fields of a class. - Getting and setting a field value. What are Auto-implemented properties? - Shortcut syntax for defining an implicit baking field with its associated property getter and setter. When should you use an auto-implemented property?   - When creating simple properties for a class. When shouldn't you use an auto-implemented property? - If the property requires any code in the getter or the setter.

Benefits of Propeties

Image
It's generally best practice to encapsulate our fields with properties.  But, why that is? With properties, Fine-grained access control, If a field is public any code can get or set the field, with the property, we can define separate accessibility for the getter and the setter.                                       For example, the getter here is internal and the setter is private so only the code within the same component can see the property and code within the same class can set it.                        in the second example, the getter is public and the setter is internal, so any code get access to the property, but only code within the code can set it. Execute code, We can execute code before returning the value or before setting the value. We can check us...