When you declare a class variable, it is initially unassigned. To use a class variable, you must create an instance of the corresponding class and assign it to the class variable. To create an instance of a class, you use the new operator.
The new operator does two things:
- It causes the CLR to allocate memory for your object
- It then invokes a constructor to initialize the fields in that object.
The version of the constructor that runs depends on the parameters that you specify for the new operator. The following code example shows how to create and use instances of the House class
House MyHouse = new House();
House YourHouse = new House();
If you call new and do not specify any parameters, the default constructor runs. Remember that if you define one or more constructors for a class, the C# compiler does not create a default constructor for you automatically.