3.6. Instantiating Objects: A Closer Look
Different OO languages differ in terms of when an object is actually instantiated (created). In C#, when we declare a variable to be of a user-defined type, such as the following, we haven't actually created an object in memory yet:
Student y;
Instead we simply declared a reference variable of type Student named y. This reference variable has the potential to refer to a Student object, but it doesn't refer to one just yet. We have to take the distinct step of using a special C# operator, the new operator, to actually carve out a brand-new Student object in memory and to then associate the new object with the reference variable y, as follows:
y = new Student();
NOTE
Behind the scenes, what we're actually ...
Get Beginning C# 2008 Objects: From Concept to Code 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.