|
|
Initialization of objects | The step after instantiation is called initialization.
Without initialization, the memory of the allocated object may contain random values.
In this context, random values is the same as garbage!
In order to avoid this, a new object should always be initialized.
In C#, constructors are responsible for initialization of the instance variables.
|
|
| Do not rely on default values! It is recommended that you bundle all initializations of instance variables in constructors. |
It is very important that a newly born object is initialized to a healthy citizen in the population of objects Explicit initialization is always preferred over implicit initialization Always initialize instance variables in constructors |
Read more about initialization in the text book version of this material. |