Constructors

The primary purpose of a constructor is to initialize an object. Initialization consists of setting the initial state of class fields. Because of definite assignment rules, it's often desirable to initialize your fields in constructors. This section shows how to gain full control over field initialization.

There are two categories of constructors: static and instance. Each category defines what fields can be initialized and the sequence of initialization. If need be, both types of constructors can be used in a single class. Just be careful to design your class properly. Using both types of constructors in the same class could be an indication of a class possibly supporting multiple roles—which may complicate a design.

Instance Constructors ...

Get C# Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.