2.6. Member Initialization

Each class data member is automatically initialized to the default value of its type. Numeric types, such as int and double, have a default value of 0. false is the default value of type bool. null serves as the default value of all reference types. This default initialization is carried out as part of the invocation of operator new.

If the default values are the appropriate initial member values, there is nothing additional for us to program—at least in terms of initialization. Otherwise, how we assign an alternative initial value depends on whether the class designer or class user designates what that value should be.

If the class designer is the one determining the alternative initial value, she can explicitly specify ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.