# How to make an Array of a selfdefined datatype

- How to make an Array of a selfdefined datatype
  - The Program
  - The Code:
    - Fmain.class
    - CCar.class
  - The Source

Each Array is of a specific datatype.
If you define a class, this class is like a datatype and an object of this class will have this datatype.
You can create an array in which you can put objects of your class. To do so, define the array like this:
var_name AS Object[]

## The Program

At start time, three objects of the class CCar are instantiated by the constructor.
The objects are then added to the array.
If you click the button, the brand of each object will be displayed.

## The Code:

### Fmain.class

    $arCar AS Object[]
    $blue AS CCar
    $red AS CCar
    $green AS CCar

    STATIC PUBLIC SUB Main()
      hForm AS Fmain
      hForm = NEW Fmain
      hForm.show
    END

    PUBLIC SUB _new()
      $blue = NEW CCar("blueCar", 300, 400.34)
      $red = NEW CCar("redCar", 200, 300.56)
      $green = NEW CCar("greenCar", 100, 200.34)
      $arCar = NEW Object[]

      $arCar.Add($blue)
      $arCar.Add($red)
      $arCar.Add($green)
    END

    PUBLIC SUB Button1_Click()
      i AS Integer
      txt AS String
      FOR i = 0 TO 2
        txt = txt & $arCar[i].getBrand() & "<br>"
      NEXT
      TextLabel1.Text = txt
    END

### CCar.class

## The Source

Download