Arrays As Instance Variables in Classes

The typical framework for a class definition seen so far in this book looks like the following:

class AnyClass
{
      <Instance Variables>
					<Methods>
					<Others>
}

The instance variables we have declared in our classes have up till now, mostly consisted of primitive types, but they can also be objects, such as System.Array objects. The following example illustrates.

Consider a simulation involving a Building class. Somehow, we want it to be implemented so that it “contains” numerous Elevator and Floor objects, just like its real counterpart. The following definition of the Building class contains declarations of two instance variables, both of type System.Array, called elevators and floors, respectively, making ...

Get C# Primer Plus now with O’Reilly online learning.

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