加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 为什么形式[…]的文字具有看似依赖于上下文的含义?

发布时间:2020-12-15 09:32:44 所属栏目:大数据 来源:网络整理
导读:考虑以下程序: {$APPTYPE CONSOLE}type TMyEnum = (enum1,enum2,enum3);var Arr: TArrayTMyEnum; Enum: TMyEnum;begin Arr := [enum3,enum1]; // -- this is an array for Enum in Arr do Writeln(ord(Enum)); Writeln('---'); for Enum in [enum3,enum1] d
考虑以下程序:

{$APPTYPE CONSOLE}

type
  TMyEnum = (enum1,enum2,enum3);

var
  Arr: TArray<TMyEnum>;
  Enum: TMyEnum;

begin
  Arr := [enum3,enum1]; // <-- this is an array
  for Enum in Arr do
    Writeln(ord(Enum));
  Writeln('---');

  for Enum in [enum3,enum1] do // <-- this looks very much like the array above
    Writeln(ord(Enum));
  Writeln('---');

  Readln;
end.

输出是:

2
0
---
0
2
---

为什么两个循环产生不同的输出?

解决方法

因为数组包含订单信息而一组不包含订单信息.

使用文档说明:

静态或动态数组的internal data format:

is stored as a contiguous sequence of elements of the component type of the array. The components with the lowest indexes are stored at the lowest memory addresses.

使用for循环is done in incremental order遍历这些索引:

The array is traversed in increasing order,starting at the lowest array bound and ending at the array size minus one.

另一方面,一套internal data format:

is a bit array where each bit indicates whether an element is in the set or not.

因此,所有这些“指示位”存储在一个相同的“值”中.这就是为什么一个集合可以是typecasted to an Integer type,以及为什么添加这些位的顺序丢失的原因:[enum3,enum1] = [enum1,enum3].

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读