靜態數組的定義方法

來源:互聯網
上載者:User
//1. 標準方法:var  MyArr: array[0..10] of Integer;  //定義靜態數組//2. 可以使用非0下標:var  MyArr: array[9..10] of Integer;  //不能提倡,這樣不容易與系統函數溝通//3. 根據預定義類型來聲明數組:type  TMyArr = array[0..10] of Integer;  //先定義一個數群組類型var  MyArr: TMyArr;  //再定義靜態數組//4. 在非過程區可以直接賦值:var  MyArr: array[0..2] of Integer = (11,22,33);//5. 多維陣列:var  MyArr: array[0..2, 0..2] of Integer;begin  //使用  MyArr[1,2] := 100;end;//6. 根據子界定義數組:type  TRange = 0..10;var  MyArr: array[TRange] of Integer;//7. 根據枚舉定義數組:type  TEnums = (Enum1,Enum2,Enum3);var  MyArr: array[TEnums] of string;begin  MyArr[Enum1] := '萬一';  ShowMessage(MyArr[Enum1]);  //萬一end;//8. 根據其他類型定義數組:var  MyArr: array[Byte] of Char;begin  MyArr[255] := #65;  ShowMessage(MyArr[255]);  //Aend;//應盡量不使用內建類型,可以建立類型:type  TNewByte = Byte;var  MyArr: array[TNewByte] of Char;begin  MyArr[255] := #65;  ShowMessage(MyArr[255]);  //Aend;//也可以使用類型別名:type  TChar = type Char;var  MyArr: array[TChar] of Byte;begin  MyArr['C'] := 255;  ShowMessage(IntToStr(MyArr['C']));  //255end;//同時定義類型:type  MyRec = record    s: string;    r: Real;    b: Byte;  end;var  Arr1: array[0..100] of MyRec;  Arr2: array[0..100] of record s: string; r: Real; b: Byte; end;  //可以直接這樣定義  Arr3: packed array[0..100] of MyRec;  //壓縮數組定義, 好像沒有區別?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.