5 simple rules to remember for the default values that class member variables get:
- Numeric data is set to 0 or 0.0
- char types are set to ‘\0’
- bool types are set to false
- string types are set to null
- Reference types are set to null
This is at the class level. When within method scope, you must assign an initial value before using a variable as they don’t receive a default assignment. The only exception is when using a variable as an output parameter (out keyword).
If you’d like to override the default values, you can assign a type’s member variable at the time of declaration:
Be aware that members are assigned before the constructor gets called. That means that if you give a member a default value but then assign it in the constructor, it cancels out the initial assignment.