I'm reading 'Effective C#, By Bill Wagner' and in Item 12 (Chapter 2, Resource Management) he speaks about Member Initializers and Assignment Statements.
He recommends using initializers to avoid uninitialized variables in custom types and not initialize variables in each constructor you define.
So it says three cases when is better not to initialize Type variables at the declaration, one of them is:
"when you are initializing the object to 0 or null":
MyValType myVal1; // initialized to 0
MyValType myVal2 = new MyValType(); // also 0
He recommends to use the case 1, for not being superfluous.
I'm still a newbie but, as I know, myVal1
will be null
and myVal2
should be an instantiated object with the corresponding properties, so
can someone explain to me what does this mean, or maybe if I missunderstood this concept?