Data Access, Properties, and Methods
- slide 10 : 29
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