October 2010
Intermediate to advanced
1920 pages
73h 55m
English
A constructor is a special class method called automatically when you create a new instance of a class. Typically, you use the constructor to initialize private fields contained in the class.
When creating a constructor in C#, you create a method with the same name as the class name. For example, the class in Listing 17.11 displays a random quotation (see Figure 17.3). The collection of random quotations is created in the component’s constructor.
Figure 17.3. Displaying a random quotation.

Listing 17.11. Quote.cs

The collection ...
Read now
Unlock full access