Class constructors are special methods that fire automatically when a class instance is created, which is similar to how the Start method runs in LearningCurve. Constructors build the class according to its blueprint:
- If a constructor is not specified, C# generates a default one. The default constructor sets any variables to their default type values—numeric values are set to zero, Booleans to false, and reference types (classes) to null.
- Custom constructors can be defined with parameters, just like any other method, and are used to set class variable values at initialization.
- A class can have multiple constructors.
Constructors are written like regular methods but with a few differences; for instance, they need to be public, have no return type, and the method name is always the class name. As an example, let's add a basic constructor with no parameters to the Character class and set the name field to something other than null.
Add...