Page 29 : 29
Object-oriented Programming in C#
Data Access, Properties, and Methods
* Accessing Data in Objects
Indirect data access
Overview of data access in C#
* Properties
Properties - Basic Use
Properties - Tricky Use
Properties in C#
Properties: Class Point with polar coordinates
Automatic Properties
Object Initialization via Properties
Summary of properties in C#
* Indexers
Indexers in C#
Associative Arrays
Example of associating Person with BankAccount
Summary of indexers in C#
* Methods
Methods in C#
Local variables in methods
Parameters
Value Parameters
Passing references as value parameters
Passing structs as value parameters
Reference Parameters
Output Parameters
Use of ref and out parameters in OOP
Parameter Arrays
Extension Methods
Methods versus Properties versus Indexers
Methods versus Properties versus Indexers
We summarize when to use methods, properties, and 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