Data Access, Properties, and Methods
- slide 29 : 29
Methods versus Properties versus Indexers
Rule of thumbs for using methods, properties and indexers
Properties
For reading and extracting of individual instance/class variables
For writing and assigning individual instance/class variables
For other kinds of data access that does not involve time consuming computations
Indexers
Like properties
Used when it is natural to access data by indexes -
array notation
- instead of simple names
Used as surface notation for associative arrays
Methods
For all other operations that encapsulate calculations on the data of the class