Page 3 : 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
Overview of data access in C#
Our interest is indirect data access. On this page we take a very broad look at data access, including direct access to data.
In C# the data of a class can be accessed in several different ways
Data access
Directly via public instance variables
Never do that!
Indirectly via properties
Clients cannot tell the difference between access via properties and direct access of instance variables
Indirectly via methods
Should be reserved for "calculations on objects"
Indirectly via indexers
Provides access by means of the notation known from traditional array indexing
Indirectly via overloaded operators
Provides access by means of the language-defined operator symbols