数组

类型初始化 / 集合

uses System.SysUtils;

type
  TEmployee = class
  public
    FirstName, LastName: string;
    constructor Create(const AFirstName,
      ALastName: string);
  end;

constructor TEmployee.Create(const AFirstName,
  ALastName: string);
begin
  FirstName := AFirstName;
  LastName := ALastName;
end;

const
  //static array of integer
  PrimeNumbers: array [0..7] of Integer =
    (2, 3, 5, 7, 11, 13, 17, 19);

  //static two-dimensional array 2 x 3
  Matrix: array [0..1, 0..2] of Integer =
    ((1, 2, 3), (4, 5, 6));

var
  GameList: TArray<string>;
  Employees: TArray<TEmployee>;
  Grid: TArray<TArray<Integer>>;
  Number: Integer;
begin
  //dynamic array of string
  GameList := ['soccer', 'hockey', 'basketball'];

  //dynamic array of Employee class
  Employees := [
    TEmployee.Create('Pavlov', 'Anton'),
    TEmployee.Create('Kirienko', 'Elena')];

  //dynamic two-dimensional array
  Grid := [[1, 2, 3], [4, 5, 6]];

  for Number in PrimeNumbers do
    Write(Number, ' ');
  WriteLn;
  WriteLn(string.Join(', ', GameList));
  WriteLn(Employees[0].FirstName);
  WriteLn(Matrix[1, 2]);
  //6

  WriteLn(Grid[0][1]);
  //2
end.