June 2003
Intermediate to advanced
624 pages
12h 41m
English
We've created objects using new like this: Customer customer = new Customer();. If you're an OOP programmer, you know those parentheses after Customer are there for a reason, because when you create an object from a class, you're using the class's constructor. A constructor is a special method that has the same name as the class and returns no value. It is used to initialize the data in the object you're creating. In C#, constructors are declared this way:
[attributes] [modifiers] identifier([formal-parameter-list]) [initializer] { constructor-body }
Here are the parts of this statement:
attributes (Optional)— Hold additional declarative information, as we'll see in Chapter 14.
modifiers (Optional)— The allowed modifiers ...