Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/10366904/within-the-containing-class-use-property-or-field">Answer by Oded</a></p> <ul> <li><p>When using Auto-Implemented properties, you don't have a choice - you must use the property, as you don't have any access to the generated field.</p></li> <li><p>If you property is not simple and does some extra work (validation, firing events etc...), you should call the property in order to centralize access and logic.</p></li> <li><p>If you have any other properties (meaning a simple property with no logic and a backing field) I would ask why are they not one of the above...</p></li> <li><p>With the example you have give, it makes little difference - it is more important to be consistent with how you use these and really boils down to personal aesthetics and coding style.</p></li> </ul> <p><a href="https://stackoverflow.com/questions/271318/should-you-access-a-variable-within-the-same-class-via-a-property">Answer by TheCodeJunkie</a></p> <ul> <li><p>One of the stronger argument for accessing local (class scope) variables through properties is that you add a level of abstraction in your class. If you change any logic concerning how that field is stored then the rest of your code will be left unaffected.</p></li> <li><p>For example you might change that from a local variable to a property of a child object, to a database call, to a webservice call, to a static property on a class and so on. When making the change it gives you a single point of change, the property, and you do not have to update the rest of your class since they all use the property.</p></li> <li><p>Also using the property enables you to apply business rules on the value of the property instead of having to enforce the same rule at each location where you'd directly access the field. Again, encapsulation</p></li> <li><p>With the introduction of automatic properties there's even less reason to explicitly have a local variable, unless you need to apply business rules on the get/set</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload