跳轉到內容

Ada 程式設計/屬性/'Length

來自華夏公益教科書,自由的教科書

Ada. Time-tested, safe and secure.
Ada。經時間考驗,安全可靠。

'Length 是一個數組型別屬性。它可以帶或不帶輸入引數使用。

不帶輸入引數時,'Length 是一個整數,表示陣列型別的第一維的長度。

帶輸入引數時,'Length(N) 是一個整數,表示陣列型別的第 N 維的長度。N 必須是一個正數,位於陣列的維度範圍內。

如果你宣告

type My_Vector is array (1 .. 7) of Integer;
type My_Matrix is array (1 .. 5, 1 .. 10) of Integer;

那麼

pragma Assert (My_Vector'Length =  7);

pragma Assert (My_Matrix'Length(1) =  5);
pragma Assert (My_Matrix'Length(2) = 10);

pragma Assert (My_Vector'Length(1) = My_Vector'Length);
pragma Assert (My_Matrix'Length(1) = My_Matrix'Length);

另請參閱

[編輯 | 編輯原始碼]

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

[編輯 | 編輯原始碼]
華夏公益教科書