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 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.