O'Reilly logo

Start Here!™ Fundamentals of Microsoft® .NET Programming by Rod Stephens

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

Constructors and Destructors

You can define all sorts of methods for a class, but there are two kinds of methods that have a very special place in an object’s lifetime: constructors and destructors.

Constructors

A constructor is a method that is called automatically when the program creates a new instance of a class. When part of the program creates a new instance of the class, the system calls the appropriate constructor before it returns the new object to the code that created it.

You can use a constructor to initialize the object’s properties and fields, get data for the object from a database, open resources, such as files, that the object will use, and generally prepare the object for use.

The syntax for constructors differs from language to ...

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