O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Instance Constructors

You have already briefly been introduced to constructors in Chapter 5, “Your First Object-Oriented C# Program,” and since then you have seen simple implementations of them in several source code examples. The following section elaborates on this earlier introduction and looks at why constructors are needed and how they are used.

Why Do We Need Instance Constructors?

When an object is created, the underlying computer memory representing its instance variables are allocated as part of this process. But just after this allocation procedure (and before any automatic or manual initializations have taken place), the memory and, hence, the instance variables only holds arbitrary garbage left over from last time this memory was ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required