--------------------------------------------------------------------------------
const arr1: array[0..9] of Integer = (1,2,3,4,5,6,7,8,9,10); arr2: array[0..1, 0..3] of Integer = ((1,2,3,4), (5,6,7,8)); var arr3: array[Boolean] of Integer; arr4: array[Byte] of Integer; begin ShowMessage(IntToStr(Length(arr1))); {10} ShowMessage(IntToStr(SizeOf(arr1))); {40}
ShowMessage(IntToStr(Length(arr2))); {2} ShowMessage(IntToStr(Length(arr2[0]))); {4} ShowMessage(IntToStr(Length(arr2[1]))); {4} ShowMessage(IntToStr(SizeOf(arr2))); {32}
ShowMessage(IntToStr(Length(arr3))); {2} ShowMessage(IntToStr(SizeOf(arr3))); {8}
ShowMessage(IntToStr(Length(arr4))); {256} ShowMessage(IntToStr(SizeOf(arr4))); {1024} end; -------------------------------------------------------------------------------- 我们倒是可以利用这个原理, 迅速知道多维数组的元素总数: --------------------------------------------------------------------------------
const arr: array[0..1, 0..2, 0..3] of Integer = (((1,1,1,1), (2,2,2,2), (3,3,3,3)), ((4,4,4,4), (5,5,5,5), (6,6,6,6))); begin ShowMessage(IntToStr(SizeOf(arr) div SizeOf(Integer))); {24} end;
|
请发表评论