October 2008
Beginner to intermediate
680 pages
16h 48m
English
When we talked about instantiating objects in the previous chapter, you may have been curious about the interesting syntax involved with the new operator:
Student x = new Student();
In particular, you may have wondered why there were parentheses tacked onto the end of the statement. It turns out that when we instantiate an object via the new operator, we're actually invoking a special type of function member called a constructor. The new operator is used to allocate the memory needed to store the data of the object. The job of the constructor is to initialize the instance variables of the object.
It turns out that if we don't explicitly declare any constructors for a class, C# automatically ...
Read now
Unlock full access