为什么在数组名称后加括号和点而不是括号? [英] Why are there parentheses and dots after an array's name instead of brackets?
问题描述
访问数组中的元素时,方括号的用法如下:
When accessing an element in an array the square brackets are used like so:
{'X is an int and Numbers is an int array'}
X := Numbers[8];
但是,在阅读其他人的代码时,有时会发现以下语法:
However, While reading others' code I sometimes find the following syntax:
{'PBox , SBox1 , SBox2 are arrays of int , And X,Y are ints'}
Result := Result or PBox(.SBox1[X] or SBox2[Y].);
- 如
PBox(someNumber)
中那样,在数组名称后加括号是什么意思?这是访问数组元素的另一种方法吗? - "是什么?在SBox1之前和之后SBox2是什么意思?SBox1和SBox2都是数组.代码编译没有错误,但我不知道这些点是什么意思.
- What does it mean to have parentheses after the array's name, as in
PBox(someNumber)
? Is this another way to access an array element? - What does the "." before SBox1 and after SBox2 mean? Both SBox1 and SBox2 are arrays. The code compiles without error but I don't know what those dots are for.
推荐答案
是的,现在我知道您的工作了.
Yes, now I see what you do.
实际上,(.
和.)
只是编写 [
和]的替代方法(但非常罕见!).
在Delphi中.
In fact, (.
and .)
are merely alternative ways (but very uncommon!) of writing [
and ]
in Delphi.
如果 PBox
是一个数组,则 PBox [a]
(或等效地, PBox(.a.)
)将需要 a
是整数,对不对?如果 SBox1 [x]
和 SBox2 [Y]
是整数,则按位的或也是整数.(按位
数组 or
是一个接受两个整数并返回新整数的操作.)因此, PBox(.SBox1 [X]或SBox2 [Y].)
是<代码>(SBox1 [X]或SBox2 [Y]) PBox
中的元素,即整数.因此,计算出 Result
与该整数之间的按位或是有意义的,这是完成的操作:
If PBox
is an array, then PBox[a]
(or, equivalently, PBox(.a.)
) would require a
to be an integer, right? And if SBox1[x]
and SBox2[Y]
are integers, so is the bitwise or
of them. (Bitwise or
is an operation that takes two integers and returns a new integer.) Hence, PBox(.SBox1[X] or SBox2[Y].)
is the (SBox1[X] or SBox2[Y])
th element in the array PBox
, that is, an integer. So it makes sense to compute the bitwise or
between Result
and this integer, which is what is done:
Result := Result or PBox(.SBox1[X] or SBox2[Y].);
这篇关于为什么在数组名称后加括号和点而不是括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!