O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required