Page 10 : 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
Object Initialization via Properties
In C# 3.0 properties can be used together with constructors to ease creation of new objects.
Class BankAccount - as short as possible.
A client of the simple BankAccount with object initializers.
An equivalent BankAccount class without object initializers.
Class BankAccount - with two constructors.
A client of class BankAccount with an object initializer.
An equivalent client of class BankAccount without object initializers.
Output of the Client program.
Class BankAccount and class Person.
A client of class BankAccount with nested object initializers.
The use of
object initializers
mimics the use of
keyword parameters
in constructors