3.7. Objects As Fields

When we first discussed the fields and methods associated with the Student class, we stated that some of the fields could be represented by predefined types provided by the C# language, whereas the types of a few others (advisor, courseLoad, and transcript) were left undefined. Let's now put what we learned about user-defined types to good use.

Instead of declaring the Student class's advisor field as simply a string representing the advisor's name, we'll declare it to be a user-defined type—namely, type Professor, another class that we invented (see Table 3-2).

Table 3.2. Student Class Fields, Revisited
FieldType
namestring
studentIdstring
birthdateDateTime
addressstring
majorstring
gpadouble
advisorProfessor
courseLoad???
transcript ...

Get Beginning C# 2008 Objects: From Concept to Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.